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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:09:27+00:00 2026-05-27T16:09:27+00:00

In a C++ code on linux x86_64, I need to double precision computing (+

  • 0

In a C++ code on linux x86_64, I need to double precision computing (+ or -).

26.100000000000001 – 26 + 0.10000000000000001

I got:

0.20000000000000143

I want to get 0.2.

here, the display format is not import, the computing results will be used for some if-else branch conditions. So, I only want the if-else conditions compare the 4 digits after the decimal digit.

It seems a rounding error ?

How to restrict the computing precision to 4 digits after decimal point ?

I do not want to call any functions in order to avoid overhead.

I do not want to use stringstream due to transformation overhead.

Any better ideas ?

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-27T16:09:28+00:00Added an answer on May 27, 2026 at 4:09 pm

    The computing precision is fine. It’s the display precision you’re trying to control. You can do that with setprecision() if using <iostream> or a formatter like "%.4f" if using <stdio.h>.

    You are already calling functions since you are displaying the result as decimal!

    P.S. 0.1 cannot be exactly represented by a float, double, or any binary-mantissa format. It factors into (1/2) * (1/5), and decimal 1/5 is an infinitely-repeating digit sequence in binary.

    P.P.S. Go look at GMP. It might be your best hope.

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

Sidebar

Related Questions

I have a C array that contains binary x86_64 machine code, which I need
Is this code snippet well defined in ANSI C? On my system (Linux x86_64)
?Is it possible to start an x86_64 code on i686 Linux (x86, 32-bit)? My
Using gcc and ld on x86_64 linux I need to link against a newer
The following C code illustrates a problem I'm seeing on Linux 2.6.30.5-43.fc11.x86_64: #include <sys/types.h>
I tried to remote debug an 32-bit application on x86_64 suse linux, but get
I have some Linux code that monitors our hardware by collecting temperatures, voltages, and
I am looking to write some C# code for linux/windows/mac/any other platform, and am
I'm trying to port some Windows code to Linux, ideally through platform-independent libraries (eg
I'm porting some crufty C++ Windows-code to Linux, which uses functions called open and

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.