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

  • Home
  • SEARCH
  • 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 495315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:34:54+00:00 2026-05-13T05:34:54+00:00

float totalAmount = 0; . . .//totalAmount assigned value 1.05 correctly . totalAmount +=

  • 0
float totalAmount = 0;
.
.
.//totalAmount assigned value 1.05 correctly
.
totalAmount  += float.Parse(dataRow["Amt"].ToString()); //where dataRow["Amt"] has value 4.93

The answer I get for totalAmount is 5.97999954 instead of 5.98

Why is this happening?

  • 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-13T05:34:54+00:00Added an answer on May 13, 2026 at 5:34 am

    You state that totalAmount is 1.05, before the accumulation. That would give expected results of:

    1.05
    4.93 +
    ------
    5.98
    

    You are getting 5.97999954, which is basically the answer as best represented by IEEE floating point, which is a binary format that cannot exactly express every decimal number. For instance, the rather common 0.110 has an infinite binary floating point representation .0001100110011...2.

    And a Wikipedia link, for good measure: http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems 😉

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

Sidebar

Related Questions

float a=67107842,b=512; float c=a/b; printf(%lf\n,c); Why is c 131070.000000 instead of the correct value
If you have a float in MSSQLServer, to what do you map this in
I'm retrieving a float value from a mysql database on a php page (2.5,
I have a (float) rating value as a percentage from 0..100 (where 50 =
float per = (num / (float)totbrwdbksint) * 100; i m getting the value of
... float value = Float.parseFloat((String)model.getValueAt(e.getLastRow(), 1)); DecimalFormat dec = new DecimalFormat(#.###); model.setValueAt(dec.format(value), e.getLastRow(), 1);
I have a float value set to NaN (seen in the Watch Window), but
I have this SQL Server query: DECLARE @HoursUsed float SELECT COLUMN_A ,(SELECT (@HoursUsed =
Doing this: float x = arc4random() % 100; returns a decent result of a
typedef float v4sf __attribute__ ((mode(V4SF))); This is in GCC. Anyone knows the equivalence syntax?

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.