[Javascript] 2 Decimal Places in Float

David Stoltz Dstoltz at SHH.ORG
Thu Apr 6 12:56:26 CDT 2006


Yes correct - that was what I was looking for (not rounding)...

Thanks!  

-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Matt Warden
Sent: Thursday, April 06, 2006 1:45 PM
To: [JavaScript List]
Subject: Re: [Javascript] 2 Decimal Places in Float

On 4/6/06, Scott Reynen <scott at randomchaos.com> wrote:
> On Apr 6, 2006, at 12:19 PM, David Stoltz wrote:
> > .02304040948378377
> >
> > How can I "format" the resulting number to only show 2 decimal 
> > places,
> > like:
> >
> > .02
>
> document.theTimer.cost.value = Math.round(  ( parseFloat(myOperator) +
> parseFloat(costToAdd) ) * 100 ) / 100;

This is close. He said he wanted it formatted, which I interpret as
chopping, not rounding. So, just in case that's what OP wanted:

var val = parseFloat(myOperator) + parseFloat(costToAdd); val =
parseInt( val * 100 ) / 100;

--
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list