von dp am 23.August 98 um 18:29:20:
zu: Director don't do no stinkin' decimals. ? von dp am 23.August 98 um 18:26:49:
The
>problem we are encountering is decimals. We can't seem to get Director
>to show prices the way they should be eg- $1.98. We get everything
>rounded to one decimal place.
>
>Any suggestions as to how we can fix this infuriating problem?
>
Try this in the message window:
put 1 + 1.44
You will see decimals. Adjust float precision if needed. look up float() in your online help.
But, you do not HAVE TO use decimals. I prefer to calulate $1.00 as simply 100, then convert the 100 to DISPLAY as $1.00 when needed. But not in this example, here I am using decimals.
To do dollar conversion, you have to do it in lingo. If values are all under 1000, and you are using decimals, here's how I have done it before:
-- example use in message window:
put ConvertToCash(44.5)
-- "$44.50"
-- the movie script:
on ConvertToCash tVal -- tVal is the incoming value (decimals in this case)
-- this float stuff only needed if you need to calc at
-- floatprecision > 2:
set tLastFloatPrecision = the floatprecision
set the floatprecision = 2
-- this does the conversion:
set tTX = string(tVal)
set totChars = the number of chars in tTX
-- next two instructions not necessary in D6
-- because it will auto pad at float prec of 2.
-- find out where the decimal is:
set periodPos = offset(".", tTX)
-- in case of a value like "4.5" we need pad it with a zero:
if totChars - periodPos = 1 then put "0" after tTX
-- in this case I needed cents or dollars:
if the number of chars in tTX < 4 then
put "¢" after tTX
else
put "$" before tTX
end if
return tTX
-- reset the float precision
set the floatprecision = tLastFloatPrecision
end
It is easy to modify this script to insert commas for values like $12,898,400. You just count chars backwards, inserting a comma as you pass 3 chars before the decimal point, and only on 10,000+ dollar values, greater than 9999.99.
D. Plänitz