<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Why does JScript have rounding errors?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/why-does-jscript-have-rounding-errors.aspx</link><description>Try this in JScript: window.alert(9.2 * 100.0);

You might expect to get 920, but in fact you get 919.9999999999999. What the heck is going on here?</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Why does JScript have rounding errors?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/why-does-jscript-have-rounding-errors.aspx#2364321</link><pubDate>Wed, 02 May 2007 01:37:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2364321</guid><dc:creator>Kaspar Karlsson</dc:creator><description>&lt;p&gt;Maestro,&lt;/p&gt;
&lt;p&gt;I must agree with Jon Kale.&lt;/p&gt;
&lt;p&gt;sometimes it's important to have an integer when it should be, and a floating point number when needed, not just because an integer is prettier.&lt;/p&gt;
&lt;p&gt;for example, if you want to calculate prime numbers, you'll have to divide the number (x) you want to check by all integers ranging from 2 - ceil(sqrt(x)) &amp;nbsp;(we call that integer y), and see what's left (z) &amp;nbsp;(thus executing z = x % y). if z == (int) 0, then you'll know that x isn't prime, as it can be divided by y w times (w being an integer and positive). however, if z is not (int) 0, you'll have to check further (by increasing y). but z can be (int) 0, plus/minus this very very very small JScript rounding error margin, making it NOT (int) 0. in that case you can't be sure wheter you have a prime number or not...&lt;/p&gt;
&lt;p&gt;of course calculating prime numbers in JScript is plain stupid when you can do that with Python several thousands times faster, but this is just an example to show that that very very very small JScript rounding error margin can make a real difference. I can think of other cases.&lt;/p&gt;
&lt;p&gt;Adios, K.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2364321" width="1" height="1"&gt;</description></item><item><title>Chronological Index</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/why-does-jscript-have-rounding-errors.aspx#427922</link><pubDate>Fri, 10 Jun 2005 23:55:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:427922</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>2003/09/12 What's Up With Hungarian Notation? 2003/09/12 Eric's Complete Guide To BSTR Semantics 2003/09/12...&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=427922" width="1" height="1"&gt;</description></item><item><title>re: VB 6 </title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/why-does-jscript-have-rounding-errors.aspx#76463</link><pubDate>Thu, 19 Feb 2004 22:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:76463</guid><dc:creator>Rob Chartier's Excogitation</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=76463" width="1" height="1"&gt;</description></item><item><title>RE: Why does JScript have rounding errors?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/why-does-jscript-have-rounding-errors.aspx#53004</link><pubDate>Tue, 23 Sep 2003 18:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53004</guid><dc:creator>Eric Lippert</dc:creator><description>&amp;gt; after all, 920 differs from 920.0:

Well, if they differ, what's their difference?  Last I checked, 920 - 920.0 = 0, add 920.0 to both sides and you get 920 = 920.0, QED.

As a mathematically inclined pedant with a degree in mathematics from the University of Waterloo, lemme tell ya, you're going to have to start from the set-theoretic underpinnings of the real number system if you want to make this argument, and it is not an argument that I myself would care to advance.  That 920 in Z and the 920 in R are the same number dude.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=53004" width="1" height="1"&gt;</description></item><item><title>RE: Why does JScript have rounding errors?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/why-does-jscript-have-rounding-errors.aspx#53003</link><pubDate>Tue, 23 Sep 2003 13:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53003</guid><dc:creator>Jon Kale</dc:creator><description>'Ultimately, the reason that this is an issue is because we as human beings see numbers like &amp;quot;920&amp;quot; as SPECIAL.'

Erm... surely you mean 'numbers like &amp;quot;920.0&amp;quot; as SPECIAL'. After all, 920 differs from 920.0: one's in Z, while the other's in R, and as any fule kno, the numbers in Z have some very interesting properties which don't generalise to R, and vice versa.

Now, this is of course a mathematically inclined pedant writing this... but even so it raises an interesting point, which is that people in the main conflate integers and rationals when they can, even when the conversion isn't necessarily valid - so VBS does the &amp;quot;least-suprise&amp;quot; thing whereas JS does the &amp;quot;right&amp;quot; thing.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=53003" width="1" height="1"&gt;</description></item><item><title>RE: Why does JScript have rounding errors?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/why-does-jscript-have-rounding-errors.aspx#53002</link><pubDate>Mon, 22 Sep 2003 00:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53002</guid><dc:creator>Eric Lippert</dc:creator><description>Hmm, that works fine for me and I don't recall ever fixing a bug in the mod operator.  Can you send me a SMALL program that reproduces the fault along with the version numbers on JScript.DLL and CScript.exe?  

Thanks,
Eric
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=53002" width="1" height="1"&gt;</description></item><item><title>RE: Why does JScript have rounding errors?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/why-does-jscript-have-rounding-errors.aspx#53001</link><pubDate>Sun, 21 Sep 2003 20:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53001</guid><dc:creator>Abhi</dc:creator><description>Hi,
Thanks for the headup :)

I used JScript in WSH for doing 108 % 100 and i got the answer as 0. i get correct answers for all the other numbers. I think this is a bug too.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=53001" width="1" height="1"&gt;</description></item></channel></rss>