April 24, 2024, 02:28:01 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Need a way to make currency variable

Started by Zooker, April 08, 2008, 04:09:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zooker

I had a formula tucked away where I could use a String for the number and then I thought divide it by .001 and It would come up with the correct number and I had to put a decimal 2 palces from the right, I  think. I any one remembers it would you please tell me how to dur it correctly?

GWS

I don't think it's worth the effort Zooker ..  :)

Some folk suggest using integers with centi-units or even milli-units to deal with cents, pence, whatever .. with string storage and treating the last two characters as following the decimal point - all in the name of accuracy.

Unless you're dealing in trillions like Fort Knox - I think your ordinary Double Float is good enough.

Consider $100.37 .. if you're going to add other monetary values to it, or subtract from it - there's no loss of accuracy.
If  you're going to multiply it by say 12 to get an annual estimate - again no problem.

On the other hand if it was a three-month total say - and you want the average per month,
you get (100.37 / 3) = 33.456666667.  :o

Then when you print the result, you'll be using 'er 'using' to set the result as $33.46 rounded to two decimal places (or more if you so desire). :)

If you had used a 'currency' type value of 10037 and divided it by 3, you'd have got 3345 (or 3346 if you rounded the integer up)
Your result then becomes (moving to make the decimal place)  $33.45 (or $33.46 if you rounded the integer division upwards).

In any case - you'd have no more accurate an answer than just using  Double in the first place ..  :)

So not worth fussing about I don't think ..  :)

all the best,

Graham


Tomorrow may be too late ..

Zooker

As usual, a lot of great information. I printed this out!!
Thank's GWS

GWS

Just to clarify another viewpoint someone might take ..  :)

Consider a value $100.21.   Seems simple enough , but try this little test program which loads the value into a Double, and prints it with precision set to 15 significant figures ..

openconsole

def v:double
setprecision 15

v = 100.21

print v

do:until inkey$<>""
closeconsole
end


The value prints as :  100.209999999999990      ::)

So we've lost an amount of  $10e-14 (ie: $0.000000000000001) -- big deal. :P

Notice that if we print the value rounded to two decimal places, it's perfectly correct at $100.21.

Maybe if you added a million or so values, and they all had lost that small amount(which they wouldn't), you might finish up with one disappeared cent ..

I don't think that's likely to happen in any financial calculation we might make ..  :)

best wishes,

Graham

Tomorrow may be too late ..