[Javascript] 2 Decimal Places in Float
Matt Warden
mwarden at gmail.com
Thu Apr 6 12:45:08 CDT 2006
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.
More information about the Javascript
mailing list