Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: "scientific notation"

From: doug:vos:eds at: 10-Jan-2003 14:44

Has everyone who complained tried the function I provided that solves the problem? It seems to be a good work around for me, so I don't know what people are still complaining about? Please help me understand... Try the function exp2dec (watch for wrapping)
>> exp2dec 1E-2
== "0.01" ;--------------------------------------------------------------------------- - exp2dec: func [ {Converts a number with a negative exponent (E-x) to its decimal bv equivalent. If the number must be converted, then a string will be returned. Otherwise the number sent to the function, N, will simply be returned.} N [number!] "The exponential number to convert." /local ret digit exp _get-dec-exp dec-numbers less-than-zero absn ][ ret: N less-than-zero: either (N < 0) ["-"][""] _get-dec-exp: func [ num [number!] /local shift _exp ][ shift: num _exp: 1 while [shift < 0.1][ shift: shift * 10 ;shifts a number until the fit _exp: _exp + 1 ] return _exp ] absn: abs(N) if (absn // 1 <> 0) [ exp: _get-dec-exp absn if (exp > 1) [ ret: make string! 10 insert/dup ret "0" (exp - 1) ;appends the zeros behind the decimal insert ret (join less-than-zero "0.") dec-numbers: make string! 10 dec-numbers: to-string absn dec-numbers: copy/part (find dec-numbers "E-") at dec-numbers 1 dec-numbers: rejoin parse dec-numbers "." foreach digit dec-numbers [ append ret digit ] ] ] return ret ] ;---------------------------------------------------------------------------