The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Javascript Bad Math

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jason Nadal

Posts: 184
Nickname: jnadal
Registered: Dec, 2003

Jason Nadal is an asp.net developer, dabbling in winforms from time to time.
Javascript Bad Math Posted: Apr 14, 2004 9:08 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jason Nadal.
Original Post: Javascript Bad Math
Feed Title: Jason Nadal
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/jnadal/Rss.aspx
Feed Description: Restless C#ding
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jason Nadal
Latest Posts From Jason Nadal

Advertisement

I really wish someone could explain to me how, in javascript, the following calculation happens:

0.2320 * 100 = 23.20000000000003

Check out the following script, which I only managed to fix by setting the precision of the offending result to 4 significant digits. The glitch can be seen with the following script:

<html>
<body> 
 <script language="javascript">
  var x = Number('0.2320');
  alert(x);
  var y = x*100;
  alert(y);
 </script> 
</body>
</html>

Read: Javascript Bad Math

Topic: What do you expect from Sun and Microsoft? Previous Topic   Next Topic Topic: How to create a Word document Form-letter-like functionality in a web application

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use