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

Re: significant figures



This should take care of most of the issues involved when rounding numbers.

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


At 02:46 PM 3/2/96 +0000, you wrote:
>Hello again
>
>I posted this question over a week ago and have had no replies so I thought
>I'd try again!
>
>Is there a way to accurately round off numbers to a given number of decimal
>places (2!) - obviously useful for any sort of monetary display field.
>
>I've looked at a fair number of examples of spreadsheets, calculators etc.
>and none of them do this!
>
>I've tried using code like
>
>              (round(100 x myNumber))/100
>
>- no good, not only do all the decimal places fill up again but also it's
>not accurate! (You typically get something like 1.99999999999 instead of 2
>etc.).
>
>Anyone out there got a definite answer on this one - "it can't be done"
>would be better than nothing!

--------------------------------------------------------------------
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/