It just came to my attention that, according to IE's Javascript engine, 0.06 + 0.01 == 0.0699999999999999, but that 0.07 + 0.01 == 0.08.
Also, (element.filters["Alpha"].opacity = 0.58) == 0.57.
Eh?
Any way around this (yet another) apparent bug?
It just came to my attention that, according to IE's Javascript engine, 0.06 + 0.01 == 0.0699999999999999, but that 0.07 + 0.01 == 0.08.
Also, (element.filters["Alpha"].opacity = 0.58) == 0.57.
Eh?
Any way around this (yet another) apparent bug?
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Alpha opacity is from 0 to 100.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Ack, I could have sworn I edited this. Sorry. Yes, I did figure that out. Though how 0.06 + 0.01 comes to be 0.06999999999999999, I've still to figure out. This actually appears in every browser; it's only in IE that it breaks the script (due to alpha opacity not working with decimals). I've sorted it with a parseInt in the right place, but still curious as to why it happened.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Hmm, the easy way around would be to make the script more IEcentric, this also would probably make for simpler math all the way around. Set and compute your numbers as whole numbers, only dividing by 100 for other browsers.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
That's expected.Originally Posted by Twey
A little more curious, but there's a golden rule that applies to such a case.Also, (element.filters["Alpha"].opacity = 0.58) == 0.57.
It's not a bug, but the inherent inaccuracy of floating-point number formats, and isn't limited to ECMAScript. Not all numbers can be represented exactly, so they may occasionly need to be approximated. Due to this problem, floating-point values shouldn't be compared for equality under most circumstances. A certain amount of error should be factored in, and a relational comparison should be used instead.Eh?
Any way around this (yet another) apparent bug?
If you want exact arithmetic, use integers, preferably using string manipulation to perform the transformation (you've seen my toCurrency function before, right?)
The comp.lang.javascript FAQ has a brief description of this, with more discussion in the group itself.
Mike
Aha, now I see. I was vaguely aware of the "precision vs. accuracy" problem, but didn't see how it applied; I hadn't considered the problem of intermediates. That's cleared it up for me, and will indubitably be very useful in the future; thanks.The comp.lang.javascript FAQ has a brief description of thisIndeed. However, the only difficulty here is in deciding in which direction to round; I'm sure no-one's going to notice a 0.00000000001 difference in every opacity step out of fifty.you've seen my toCurrency function before, right?![]()
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Switch to integers, you can see examples of this in several DD scripts.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Literally, 0.06 + 0.01 = 0.07, NOT 0.06999999999999...
Last edited by tech_support; 04-20-2007 at 02:23 AM.
....(o_ Penguins
.---/(o_- techno_racing
+(---//\-' in
.+(_)--(_)' The McMurdo 500
Since we seem to be resurrecting this old thread, I thought I might just throw in here that, for many years 'Calculator', which has shipped with Widows (misspelling intentional) from the very beginning, was inaccurate with these or some other basic types of math problems. They finally fixed this late in the reign of 3.01 or, actually I think, 98.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
But isn't the fix to actually calculate the expression to 14 decimal places then round the display to 12 decimal places.
If the 14 decimal places are 0.69999999999999 then to 12 places this is 0.7 ?!?
Bookmarks