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

Time, seconds and scientific notation

 [1/11] from: hallvard::ystad::oops-as::no at: 23-Feb-2004 21: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)? Thanks, HY

 [2/11] from: SunandaDH:aol at: 23-Feb-2004 16:18


Hallvard:
> How can I have the second example printed without scientific notation (as > seconds)?
I suspect you are running under Windows. Other platforms don't go scientific for just 2 decimal places. Windows does, even for non-time values: print .01
>> print .01
1E-2 I don't think there is an easy solution, other than to write a decimal formatter yourself. Here's a cheap Windows trick -- assuming you only want 2 decimal places:
>> print replace mold to money! .01 "$" ""
0.01 Sunanda.

 [3/11] from: maximo:meteorstudios at: 23-Feb-2004 16:35


if you have an old version of my steel utils, there is a as-string type converter which will convert decimals to strings with a user selected number of digits after the decimal point... other wise, you'll have to wait for me to find it... and send it to rebol.org later tonight. -MAx --- You can either be part of the problem or part of the solution, but in the end, being part of the problem is much more fun.

 [4/11] from: hallvard:ystad:oops-as:no at: 23-Feb-2004 23:22


Dixit [SunandaDH--aol--com] (22.18 23.02.2004):
>Hallvard: >> How can I have the second example printed without scientific notation (as >> seconds)? > >I suspect you are running under Windows. Other platforms don't go scientific >for just 2 decimal places. Windows does, even for non-time values:
Ah! Problem solved. I'm on a MacOSX, just testing things on a win2k. Phew.. Thanks. HY

 [5/11] from: atruter:labyrinth:au at: 24-Feb-2004 11:23


> Here's a cheap Windows trick -- assuming you only want 2 decimal places: > >> print replace mold to money! .01 "$" "" > 0.01
Nice, a good candidate for the REBOL one-liner's I'd say. ;) Regards, Ashley

 [6/11] from: gchiu:compkarori at: 24-Feb-2004 8:19


Hallvard Ystad wrote.. apparently on 23-Feb-2004/21:00:15+1:00
>Hi list, >This is from a console session:
<<quoted lines omitted: 3>>
>== 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 -- Graham Chiu http://www.compkarori.com/cerebrus

 [7/11] 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,
<<quoted lines omitted: 8>>
> 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

 [8/11] from: hallvard:ystad:oops-as:no at: 24-Feb-2004 10:32


Dixit Carl Read (09.23 24.02.2004):
>This discussion has got me experimenting a bit. Look at this, for >instance...
<<quoted lines omitted: 6>>
>>> time >== 1:01:00.00001
Well, but when you try to access only the seconds here (after doing the above):
>> time/second
== 1E-5 HY

 [9/11] from: tomc:darkwing:uoregon at: 24-Feb-2004 10:58


the belated but unhelpful answer you have likley heard by now is: 'dont use windows' since this is strictly an artifact of MS On Mon, 23 Feb 2004, Hallvard Ystad wrote:

 [10/11] from: carl:cybercraft at: 25-Feb-2004 9:43


On 25-Feb-04, Tom Conlin wrote:
> the belated but unhelpful answer you have likley heard by now is: > 'dont use windows' > since this is strictly an artifact of MS
Actually, I'd consider this a REBOL problem. It's supposed to be a cross-platform language afer all, and numbers should not come out different on different systems. Carl Read.
> On Mon, 23 Feb 2004, Hallvard Ystad wrote: >> Hi list,
<<quoted lines omitted: 11>>
>> To unsubscribe from this list, just send an email to >> [rebol-request--rebol--com] with unsubscribe as the subject.
-- Carl Read

 [11/11] from: atruter:labyrinth:au at: 25-Feb-2004 13:18


> Actually, I'd consider this a REBOL problem. It's supposed to be a > cross-platform language afer all, and numbers should not come out > different on different systems.
I'll second that and point to file! as a good example of how platform differences are / should be handled. Regards, Ashley

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted