Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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: Netscape 2.x

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'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.