lse123
12-10-2007, 01:56 PM
What js function to use to get a number with many decimal digits[776.986578932245] to a number with two decimal digits[776.98] ?
|
||||
number with two decimal digitslse123 12-10-2007, 01:56 PM What js function to use to get a number with many decimal digits[776.986578932245] to a number with two decimal digits[776.98] ? A1ien51 12-10-2007, 03:29 PM Look up toFixed() Eric Philip M 12-10-2007, 04:44 PM var x = 776.986578932245; var y = x.toFixed(2); alert (y); alert (typeof y) // note result is a string lse123 12-10-2007, 07:08 PM exist any other function of type: y=function(x) ; // x=776.986578932245 y=776.98 rnd me 12-10-2007, 07:35 PM sure. function to2(x){return parseFloat(x.toFixed(2));} Trinithis 12-10-2007, 07:46 PM Or . . . Number.prototype.round = function(x) { x = Math.pow(10, x); return Math.round(this * x) / x; }; (7.569).round(2); //7.57 (7.561).round(2); //7.56 var x = 0.123456; x.round(0); //0 x.round(3); //0.123 |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum