From
Armin Brunwinkel@21:1/5 to
All on Fri Jan 29 02:41:57 2021
Hi Jack,
just 'quick and dirty' :
LOCAL cDigit AS STRING
LOCAL cScience AS STRING
LOCAL lsnsetting AS LOGIC
LOCAL nValue AS FLOAT
LOCAL nFloat AS FLOAT
LOCAL nFactor AS SHORTINT
LOCAL nPOW AS DWORD
? 'See the problem...'
? POW( 10 , 9 ) , ' Working...'
? POW( 10 , 10 ) , ' ...not'
? Transform( POW( 10 , 10 ) , '99999999999' ) , ' Working'
? Transform( POW( 10 , 11 ) , '999999999999' ) , ' Working'
? Transform( POW( 10 , 12 ) , '9999999999999' ) , ' Working,...'
? '-----------------------------'
? nValue := 1234567890.00 , ' Working example for SetScience() (see VO Help)...'
lsnsetting := SetScience()
SetScience(TRUE)
? nValue
SetScience(FALSE)
? nValue
SetScience(lsnsetting )
? nValue := 12345678901.00 , ' ..not working example for SetScience())' lsnsetting := SetScience()
SetScience(TRUE)
? nValue
SetScience(FALSE)
? nValue
SetScience(lsnsetting )
? '-----------------------------'
? 'Your example 5.1E+17 ( or 5.1E-17 )'
cScience := '5.1E+17' // Or '5.1E-17'
' A kind of fracking...'
? nValue := Val( Left( cScience , At( 'E' , cScience ) - 1 ) )
IF At( '-' , cScience ) > 0
? nFactor := -1
ELSE
? nFactor := 1
ENDIF
? nPOW := Val( StrTran( StrTran( SubStr( cScience , At( 'E' , cScience ) + 1 ) , '+' , '' ) , '-' , '' ) )
? Transform( POW( 10 , nPOW ) , Replicate( '9' , nPOW + 1 ) ) , ' Working as seen above'
? nValue * POW( 10 , 3 ) , ' Working...'
? nValue * POW( 10 , 4 )
? nValue * POW( 10 , 5 )
? nValue * POW( 10 , 6 )
? nValue * POW( 10 , 7 )
? nValue * POW( 10 , 8 )
? nValue * POW( 10 , 9 )
? nValue * POW( 10 , 10 ) , ' .. not'
nFloat := Round( nValue , 1 ) * POW( 10 , 10 )
? Transform( nFloat , Replicate( '9' , nPOW + 1 ) ) , ' Working as seen above'
? 'At least ..'
IF nFactor < 0
nFloat := Round( -1* nValue * 10 , 0 )
nFloat := nFloat * POW( 10 , nPOW - 1 )
? cDigit := Transform( nFloat , Replicate( '9' , nPOW + 2 ) )
? '...and backwards to scientific...'
? cScience := SubStr( cDigit , 2 , 1 ) + "." + SubStr( cDigit , 3 , 1 ) + 'E-' + LTrim( Str( Len( SubStr( cDigit , 4 ) ) + 1 , 3 ) )
ELSE
nFloat := Round( nValue * 10 , 0 )
nFloat := nFloat * POW( 10 , nPOW - 1 )
? cDigit := Transform( nFloat , Replicate( '9' , nPOW + 1 ) )
? '...and backwards to scientific...'
? cScience := SubStr( cDigit , 1 , 1 ) + "." + SubStr( cDigit , 2 , 1 ) + 'E+' + LTrim( Str( Len( SubStr( cDigit , 3 ) ) + 1 , 3 ) )
ENDIF
Armin
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)