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

[REBOL] Re: Time, seconds and scientific notation

From: carl:cybercraft at: 24-Feb-2004 14:33

On 24-Feb-04, Graham Chiu wrote:
> Hallvard Ystad wrote.. apparently on 23-Feb-2004/21:00:15+1:00 >> Hi list, >> This is from a console session: >>>> third 0:00:01.09 >> == 1.09 >>>> third 0:00:0.09 >> == 9E-2 >> How can I have the second example printed without scientific >> notation (as seconds)? > Here's a function from Gabriele that does this in case someone else > needs it. > http://www.compkarori.com/vanilla/display/form-decimal.r
This discussion has got me experimenting a bit. Look at this, for instance...
>> dec: 0.00001
== 1E-5
>> time: 1:01
== 1:01
>> time/second: dec
== 1E-5
>> time
== 1:01:00.00001 So REBOL can output non-scientific notation of more than two decimal points, even on Windows. Which allows us to make quite a simple formating function... form-dec: func [num /local dec int][ either zero? dec: num - int: to-integer num [ form num ][ if all [negative? num zero? int][int: "-0"] join int find/last form to-time reduce [0 0 dec] #"." ] ]
>> form-dec 0.01
== "0.01"
>> form-dec 0.00001
== "0.00001"
>> form-dec 100.00001
== "100.00001"
>> form-dec -0.01
== "-0.01"
>> form-dec -0.00001
== "-0.00001"
>> form-dec -100.00001
== "-100.00001" It won't handle large numbers though, because to-integer can't...
>> 1234567891234567
== 1.2345678912346E+15
>> form-dec 1234567891234567
** Math Error: Math or number overflow ** Where: to-integer ** Near: to integer! :value -- Carl Read