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 6853175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:28:50+00:00 2026-05-27T01:28:50+00:00

Possible Duplicate: Why can't decimal numbers be represented exactly in binary? When I enter

  • 0

Possible Duplicate:
Why can't decimal numbers be represented exactly in binary?

When I enter 0.1 as a double value the compiler is adding a tiny value on the end of it that is causing other calculations to go wrong in the program that I am running. My code simply says:

double temp = 0.1;

And I get this in variable viewer:
http://img.skitch.com/20111122-nnrcgi4dtteg8aa3e8926r3fd4.jpg

Does anyone know why this is happening?

Thanks

  • 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-27T01:28:50+00:00Added an answer on May 27, 2026 at 1:28 am

    double is a floating binary point type. In binary, the value of “a half” is 0.1, and the value of “a quarter” is 0.01 etc. There is no way of exactly representing “a tenth” in a finite binary representation, any more than you can exactly represent “a third” in decimal. The compiler is giving you the closest value it can to the value you’ve actually asked for.

    If you want to store decimal values precisely because you care about the decimals (e.g. for current) you should use a decimal-based type such as NSDecimalNumber, or an integer scaled appropriately (e.g. storing 15 for 15 cents instead of 0.15 dollars).

    I have articles on binary and decimal floating point in .NET – NSDecimalNumber in Objective-C is slightly different to decimal in C# (see the documentation), but hopefully those articles will give you a bit more insight into what’s actually happening.

    EDIT: As noted in comments, typically decimal floating point types are significantly slower than binary floating point types, partly because they’re often larger and partly because they don’t have CPU support. If you have a hard performance requirement and you want to retain digits precisely, the “integer and implied scale” option is usually a good one, though a pain to code against as you need to take it into account every time you read the code 🙂

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

Sidebar

Related Questions

Possible Duplicate: Why can't decimal numbers be represented exactly in binary? I am trying
Possible Duplicate: Why can't decimal numbers be represented exactly in binary? i get very
Possible Duplicate: Why can't decimal numbers be represented exactly in binary? I am developing
Possible Duplicate: Is JavaScript's Math broken? Why can't decimal numbers be represented exactly in
Possible Duplicate: How to format a decimal How can I limit my decimal number
Possible Duplicate: c# - How do I round a decimal value to 2 decimal
Possible Duplicate: Why can't I unbox an int as a decimal? Okay, C#/.NET gurus,
Possible Duplicate: Can I use a binary literal in C or C++? I am
Possible Duplicate: How to determine if a decimal/double is an integer? I have a
Possible Duplicate: c# - How do I round a decimal value to 2 decimal

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.