View Single Post
Old 08-22-2008   #3 (permalink)
Dr J R Stockton


 
 

Re: Display Number (Amount) Properly

In microsoft.public.scripting.vbscript message <45B8F8CD-884A-4129-8D22-
47AC06AC518D@xxxxxx>, Fri, 22 Aug 2008 04:54:01, Leona Leal
Educator <LeonaLealEducator@xxxxxx> posted:
Quote:

>Kind of new at this so I do not know all of the correct script keywords.
>
>How do you display an amount as currency properly when the number is 5.6
>
>I have Response.Write "$" & Amount & " is what you owe the school district"
>
>Sorry, I would like for it to display as $5.60. It currrently display as
>$5.6 I have not done enough scripting to learn how to do this. Naturally
>when the amount does not end in 0 it works.
If you are doing arithmetic, even addition, with numbers like 5.6 / 5.60
then results may not be accurate, because such numbers cannot be stored
exactly as IEEE Doubles. Try document.write 0.01 + 0.06 - 0.07 for
example. Commonly, display rounding will give the right value; but it
may be unwise to rely on that. You don't want something that usually
works.

Do your calculations in integer pence, and if you use no fractional
pence all will be exact. Convert the result X to String - CStr(X) -,
add leading zeroes if needed to make the length at least three, insert a
decimal point, and display.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3 6.20 ; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
My System SpecsSystem Spec