Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
FAQ Topic - Why does simple decimal arithmetic give strange results? (2008-06-21)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
FAQ server  
View profile  
 More options Jun 20 2008, 7:00 pm
Newsgroups: comp.lang.javascript
From: "FAQ server" <javascr...@dotinternet.be>
Date: Fri, 20 Jun 2008 23:00:02 +0000
Local: Fri, Jun 20 2008 7:00 pm
Subject: FAQ Topic - Why does simple decimal arithmetic give strange results? (2008-06-21)
-----------------------------------------------------------------------
FAQ Topic - Why does simple decimal arithmetic give strange
results?
-----------------------------------------------------------------------

For example, 5*1.015 does not give exactly 5.075 and 0.06+0.01 does
not give exactly 0.07 in javascript.

Javascript numbers are represented in binary as IEEE-754 (IEC 559)
Doubles, with a resolution of 53 bits, giving an accuracy of
15-16 decimal digits; integers up to about 9e15 are precise, but
few decimal fractions are.  Given this, arithmetic is as exact
as possible, but no more.  Operations on integers are exact if
the true result and all intermediates are integers within that
range.

In particular, non-integer results should not normally be
compared for equality; and non-integer computed results
commonly need rounding; see 4.6.

http://msdn2.microsoft.com/en-us/library/7wkd9z69.aspx

http://www.merlyn.demon.co.uk/js-misc0.htm#DW4

Otherwise, use Math.round on the results of expressions which
should be of integer value.

--
 Postings such as this are automatically sent once a day.  Their
 goal is to answer repeated questions, and to offer the content to
 the community for continuous evaluation/improvement.  The complete
 comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
 The FAQ workers are a group of volunteers.  The sendings of these
 daily posts are proficiently hosted by http://www.pair.com.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dr J R Stockton  
View profile  
 More options Jun 21 2008, 4:07 pm
Newsgroups: comp.lang.javascript
From: Dr J R Stockton <j...@merlyn.demon.co.uk>
Date: Sat, 21 Jun 2008 21:07:04 +0100
Local: Sat, Jun 21 2008 4:07 pm
Subject: Re: FAQ Topic - Why does simple decimal arithmetic give strange results? (2008-06-21)
In comp.lang.javascript message <485c3675$0$90273$14726...@news.sunsite.
dk>, Fri, 20 Jun 2008 23:00:02, FAQ server <javascr...@dotinternet.be>
posted:

> The FAQ workers are a group of volunteers.

That needs to be changed.  At present they are effectively an empty set.

--
 (c) John Stockton, nr London, UK.    ?...@merlyn.demon.co.uk     Turnpike v6.05.
 Web  <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
 Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »