|
Q1072 Netscape 2 rounding error
irt.org | Knowledge Base | JavaScript | Bugs | Q1072 [ previous next ]
Q1072 Netscape 2 rounding error
Symptom: I have not personally seen it and the eval in the
workaround will crash Netscape Navigator 2.00 (try setTimeout instead) but here it is
anyway.
Affects:
Workaround:
<SCRIPT>
// Fixing rounding bug in Netscape 2
function roundIt(value) {
var newFullAmount, newDecimals;
if (value<=0.99) newFullAmount = '0';
else newFullAmount = parseInt(value);
newDecimals = parseInt((value+.0008 - newFullAmount)* 100);
if (eval(newDecimals) <= 9) newDecimals='0'+newDecimals;
newString = newFullAmount + '.' + newDecimals;
return (newString);
}
</SCRIPT>
|
Feedback on 'Q1072 Netscape 2 rounding error'
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.