Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:16:46+00:00 2026-05-28T06:16:46+00:00

PFB an example code snippet illustrating the issue: var x=0.323; var cumulativeVal = 0;

  • 0

PFB an example code snippet illustrating the issue:

        var x=0.323;
        var cumulativeVal = 0;

        for(i=0;i<30;i++){
                   cumulativeVal = cumulativeVal + x;
                   console.log(cumulativeVal);
        }

The result of the above computation is

  0.323
  0.646
  0.9690000000000001
  1.292
  1.615....
  4.845000000000001
  5.168000000000001
  5.491000000000001
  5.814000000000002....
  9.690000000000007

Note that an extra decimal value is getting added. I do understand that this has something to do with precision of values in javascript. But can anyone explain?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:16:46+00:00Added an answer on May 28, 2026 at 6:16 am

    There’s nothing particular to explain. IEEE-754 double-precision numbers are not completely, perfectly precise in decimal terms. Small errors can creep in. For full decimal precision (which, you should note, cannot perfectly represent one-third) you’d need to use a type designed for that. (JavaScript doesn’t have one built in; examples from other languages would be BigDecimal from Java, or decimal from C#.)

    There’s an easier example, by the way:

    0.1 + 0.2 = 0.30000000000000004
    

    It’s one of Crockford’s favorites.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, only half the records which are searched for is getting deleted. PFB the
Is the following int BlkArray::GetNthBlockA(unsigned int n, const Block *&pfb, int &maxIndex) const {
I am compiling with MinGW in Windows 7, using Code::Blocks as the IDE. Everything
My Db column in a string (varchar) and i need to assign it to
I want to allow a user of my web-app to be able to post
I have a web site done using codeigniter php framework and mysql, i have
I'm trying to bind the SelectedItem to a View. But the view is not
I am trying to build a small WCF service and wanted to utilize it
I am using Python YouTube API to retrieve information from a few video ids.
double p1::root(double (*pf)(double k), int a, int b, double e) im not sure how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.