Jump to content
Rskm

number format in scientific format

Recommended Posts

Rskm

hi, i have the following function to get a number in scientific format.

my input is 12360

what i get using the below function = 1.236E+004

What i require is 1.236E4

 

 how do i achieve this. i do not require the '+00'prefixing '4 or whatever' in my o/p. 

 

Func _FXTY($inumber)

             return stringformat("%01.3E",$inumber)

Endfunc

Share this post


Link to post
Share on other sites
funkey
Local $var = 0.0001236000000

ConsoleWrite(_FXTY($var) & @CRLF)
ConsoleWrite(_FXTY_old($var) & @CRLF)

$var = 1236000000

ConsoleWrite(_FXTY($var) & @CRLF)
ConsoleWrite(_FXTY_old($var) & @CRLF)

Func _FXTY($inumber)
    Local $s = stringformat("%01.3E",$inumber)
    Local $a = StringSplit($s, "E")
    Return $a[1] & "E" & Int($a[2])
Endfunc

Func _FXTY_old($inumber)
    Return stringformat("%01.3E",$inumber)
Endfunc

 

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
Rskm
On 3/26/2018 at 2:22 PM, funkey said:
Local $var = 0.0001236000000

ConsoleWrite(_FXTY($var) & @CRLF)
ConsoleWrite(_FXTY_old($var) & @CRLF)

$var = 1236000000

ConsoleWrite(_FXTY($var) & @CRLF)
ConsoleWrite(_FXTY_old($var) & @CRLF)

Func _FXTY($inumber)
    Local $s = stringformat("%01.3E",$inumber)
    Local $a = StringSplit($s, "E")
    Return $a[1] & "E" & Int($a[2])
Endfunc

Func _FXTY_old($inumber)
    Return stringformat("%01.3E",$inumber)
Endfunc

 

thanks. that helped

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • FireFox
      By FireFox
      Hi,
      I would like to know if it's possible to convert a number with the function StringFormat in order to place a space (or whatever) at the thousands pos.

      e.g :

      1000000 ;before 1 000 000 ;after
      Please don't suggest a solution with some strings functions, the point of this topic is to know how to do it with the function StringFormat since what I've found on internet does not work.

      Thanks for anyhelp;

      Br, Firefox.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.