R
Richard Cranium
Using the number 1.015 [many numbers having a 5 at the third decimal point
could be used but not all]
*****************************
the following script returns 1.02, which is correct
var T;
var S=new String(Math.round(parseFloat(1.015).toFixed(2)*100));
while (S.length<2) S='0'+S
var temp2 = S.substr(0, T=(S.length-2)) + '.' + S.substr(T, 2);
temp2 = 1.02
but it causes .005 - .009 to return .00, which is wrong
*****************************
******************************
the following script returns 1.01, which is wrong
var T;
var S=new String(Math.round(parseFloat(1.015)*100));
while (S.length<2) S='0'+S
var temp2 = S.substr(0, T=(S.length-2)) + '.' + S.substr(T, 2);
temp2 = 1.01
but it causes .001 - .004 to return .00, which is correct
and .005 - .009 to return .01, which is also correct
******************************
Do you have any ideas as to why it is this way, and if there is a better
[more exact] way to round numbers, these methods seem a little inconsistent.
I'll use method 1 because anything past .009 rounds correctly but what's up
with .005 - .009 rounding to .00 and not .01.
Method 2 just has way to many numbers that round incorrectly.
--
could be used but not all]
*****************************
the following script returns 1.02, which is correct
var T;
var S=new String(Math.round(parseFloat(1.015).toFixed(2)*100));
while (S.length<2) S='0'+S
var temp2 = S.substr(0, T=(S.length-2)) + '.' + S.substr(T, 2);
temp2 = 1.02
but it causes .005 - .009 to return .00, which is wrong
*****************************
******************************
the following script returns 1.01, which is wrong
var T;
var S=new String(Math.round(parseFloat(1.015)*100));
while (S.length<2) S='0'+S
var temp2 = S.substr(0, T=(S.length-2)) + '.' + S.substr(T, 2);
temp2 = 1.01
but it causes .001 - .004 to return .00, which is correct
and .005 - .009 to return .01, which is also correct
******************************
Do you have any ideas as to why it is this way, and if there is a better
[more exact] way to round numbers, these methods seem a little inconsistent.
I'll use method 1 because anything past .009 rounds correctly but what's up
with .005 - .009 rounding to .00 and not .01.
Method 2 just has way to many numbers that round incorrectly.
--