Jump to content

number format in scientific format


Rskm
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
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
 Share

×
×
  • Create New...