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

The Archive Base Latest Questions

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

I have a problem with float numbers precision: int main(void) { double b =

  • 0

I have a problem with float numbers precision:

int main(void) {
  double b = 106.829599;
  float a = b;
  std::cerr << std::setprecision(6) << "a = " << a << "; b = " << b << std::endl;
  std::cerr << std::setprecision(7) << "a = " << a << "; b = " << b << std::endl;
}

result is:

a = 106.83; b = 106.83

a = 106.8296; b = 106.8296

So, my question is why numbers in first line are so short (I was expecting to see 106.829)

gcc 4.1.2, also I made a test at LWS

  • 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-28T13:50:30+00:00Added an answer on May 28, 2026 at 1:50 pm

    Actually, 106.829599 rounded to 6 digits (3 decimals) is 106.830, which is displayed as 106.83 since 6 digits precision given to setprecision is only a maximum value.

    The decimal precision determines the maximum number of digits to be
    written on insertion operations to express floating-point values.

    What you may be looking for is combining setprecision with fixed.

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

Sidebar

Related Questions

I have a problem with the mapping of Oracle Float double precision datatype to
#include <stdio.h> #include <math.h> int main (void) { float inches; printf(Enter the number of
I have a problem with the addition of two float numbers. Code below: float
Possible Duplicate: Python rounding error with float numbers I have a rounding Problem in
I have an annoying CSS layout problem. I'm trying to float images on a
I have a code for reading files with float numbers on line stored like
I've written an iPhone-App and encountered a problem concerning typecasting between float and int.
I have an interval consisting of two float numbers, and need to generate 20
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names

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.