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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:16:16+00:00 2026-05-16T02:16:16+00:00

http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/ I have been about this lately to review C++. In general computing class

  • 0

http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/
I have been about this lately to review C++.

In general computing class professors tend not to cover these small things, although we knew what rounding errors meant.

Can someone please help me with how to avoid rounding error?

The tutorial shows a sample code

#include <iomanip>
int main()
{
    using namespace std;
    cout << setprecision(17);
    double dValue = 0.1;
    cout << dValue << endl;
}

This outputs

0.10000000000000001

By default float is kept 6-digits of precisions. Therefore, when we override the default, and asks for more (n this case, 17!!), we may encounter truncation (as explained by the tutorial as well).
For double, the highest is 16.

In general, how do good C++ programmers avoid rounding error?
Do you guys always look at the binary representation of the number?

Thank you.

  • 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-16T02:16:17+00:00Added an answer on May 16, 2026 at 2:16 am

    The canonical advice for this topic is to read “What Every Computer Scientist Should Know About Floating-Point Arithmetic”, by David Goldberg.

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

Sidebar

Related Questions

As mentioned in this tutorial: http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/ In computer programming, a stack is a container
//This program is taken from http://www.learncpp.com/cpp-tutorial/114-constructors-and-initialization-of-derived-classes/ #include <iostream> using namespace std; class A {
From http://www.learncpp.com/cpp-tutorial/19-header-files/ How does the linker know that it needs to include the standard
From http://www.learncpp.com/cpp-tutorial/97-overloading-the-increment-and-decrement-operators/ Class declaration class Digit { private: int m_nDigit; public: Digit(int nDigit=0) {
Code example from http://www.learncpp.com/cpp-tutorial/812-static-member-functions/ : class Something { private: static int s_nValue; }; int
From http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/ , code such as class Base { public: virtual void function1() {};
At: http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/ It has the following code: // Declare a DateStruct variable DateStruct sToday;
At the end of the artile here: http://www.learncpp.com/cpp-tutorial/45-enumerated-types/ It mentions the following sentence: Finally,
At the end of the article here: http://www.learncpp.com/cpp-tutorial/45-enumerated-types/ , it mentions the following: Finally,
From http://www.learncpp.com/cpp-tutorial/142-function-template-instances/ class Cents { private: int m_nCents; public: Cents(int nCents) : m_nCents(nCents) {

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.