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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:12:05+00:00 2026-06-05T16:12:05+00:00

Possible Duplicate: Floating point issue in C #include<stdio.h> main() { int a,b; float f;

  • 0

Possible Duplicate:
Floating point issue in C

#include<stdio.h>
main()
{
        int a,b;
        float f;
        scanf("%2d%3d%4f",&a,&b,&f);
        printf("%d %d %f",a,b,f);
}

When i run this program and input 2 4 56.8 ,it gives output 2 4 56.799999…..but I would expect 2 4 56.8….why is it so???

  • 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-06-05T16:12:07+00:00Added an answer on June 5, 2026 at 4:12 pm

    That is correct. Floating point numbers are approximations. Just as 0.33333333 is an approximation to 1/3, 56.7999999 is an approximation for 56.8. There is no exact floating point representation for 0.1.

    See some of what has been written:

    • http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
    • http://www.hack3r.com/forum-topic/what-every-programmer-should-know-about-floating-point-arithmetic
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: strange output in comparision of float with float literal #include<stdio.h> int main()
Possible Duplicate: Floating point inaccuracy examples PHP rounding issue - Is this a bug?
Possible Duplicate: Floating point comparison When I run the code below I get the
Possible Duplicate: Strange floating-point behaviour in a Java program I came across this weird
Possible Duplicate: Java floating point arithmetic What is special about this double math in
Possible Duplicate: Dealing with accuracy problems in floating-point numbers Code: float flt = 78983636;
Possible Duplicate: How is floating point stored? When does it matter? Using the built-in
Possible Duplicate: C compiler bug (floating point arithmetic)? I've got two doubles which I
Possible Duplicate: Floating point inaccuracy examples double a = 0.3; std::cout.precision(20); std::cout << a
Possible Duplicate: Retain precision with Doubles in java Floating point inaccuracy examples I know

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.