Director don't do no stinkin' decimals. ?


[ Zettels Traum ] [ search / suche ]

von dp am 23.August 98 um 18:26:49:

Subject: Re: decimals? Director don't do no stinkin' decimals.
To: DIRECT-L@UAFSYSB.UARK.EDU

Surrender is premature:

-- given aFloat = an integer or floating point number
-- precision = the number of decimals (assumes precision > 0 )
--
on fixDecimals aFloat, precision

put string(float( aFloat )) into str-- assures a "." in the str
put offset(".", str ) into pos
put char 1 to pos - 1 of str into int
put char pos + 1 to length( str ) of str into dec

if length( dec ) "1.90"
put "$" & fixdecimals( 3, 2 )
--> "$3.00"
put "$" & fixdecimals( 1.9773, 2 )
--> "$1.97"

Tedious, to be sure, but the safest way to assure the proper display of
numbers is to display them as strings.

BTW, check the floatPrecision, it may be set to 1 (I have no idea why.) The
default float precision is:

put the floatPrecision
--> 4

Note that fixDecimals does *not* round up to the nearest decimal, but you can:

put 3.456789 into num
-- this will round the above number to 2 decimals
set the floatPrecision to 2
put fixDecimals( num, 3 )
--> "3.460"

Noah Sepsewol
Noah's Arkive



Dazu:























D. Plänitz