Newer browsers provide a new toFixed() function that does the trick:
var myVar = new Number(4.12345678);
var x = myVar.toFixed(3); // x = 4.123
For older browsers, a slightly more cumbersome method in needed:
var myVar = 4.12345678;
var x = parseInt(myVar * 1000) / 1000; // x = 4.123
Sunday, January 17, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment