[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Number formatting problems


function roundDollar (Val) {
	Dollar = Math.floor(Val) 
	Val = "" + Math.round(Val * 100)
	Decimal = Val.substring (Val.length-2, Val.length)
	return (Dollar + "." + Decimal);

Pass your value through this function before you want to display it.  Once
passed through the function it's a string, so you can't do math with it.  

-- Gordon

At 06:02 PM 3/18/96 -0800, you wrote:
>I have a modified javascript that is a form which calculates order totals,
>quantity discounts, etc. I'm not a javascript person, and know just enough
>to modify it to make it work for me. The numbers (such as 14.95) return as
>14.94999999999999929. Is there anyway to round it up and truncate it to two
>decimal places? I've attached the file, and would appreciate examples based
>upon it if possible. When using the HTML file, type 119 under ITEM to see
>the problem. You'll notice that under PRICE, AMOUNT, TOTAL, DISCOUNT and
>GRAND TOTAL the number is a bit lengthy!
-- Gordon

For help about the list, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.
List archives and pointer to FAQ: http://www.obscure.org/javascript/