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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:09:35+00:00 2026-05-12T15:09:35+00:00

Obviously this is just a fraction of the code. printf(Please enter a positive number

  • 0

Obviously this is just a fraction of the code.

printf("Please enter a positive number that has a fractional part with three or more decimal places\n");
scanf("%5.2d", &x);
printf("The number you have entered is %5.2d\n" ,x);

Would this automatically round the number I type in? Or is there another way to do this?

Edit:

printf("Please enter a positive number that has a fractional part with three or more decimal places\n");
scanf("%lf", &x);
x = x + 0.05;
printf( "The number you have entered is %5.2lf\n", x);

Iv done this, but Im taking into consideration what someone had said about printf just “changing” the way it reads out. So this is obviously not the right way. Should I implement maybe the pow() function? Will that work with this somehow?

Edit2:

printf("Please enter a positive number that has a fractional part with three or more decimal places\n");
scanf("%lf", &x);
x = x + 0.05;
printf( "The number you have entered is %5.2lf\n", x);

Okay, iv gotten to the point where if i imput a number it will round to a whole number. 35.21 will round to 35, and 35.51 will round to 36 et. etc.

How would I get 35.2178 to round to 35.22, and 35.2135 to round to 35.21.
How would I get the certain powers of the decimal to round instead of the whole number?

  • 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-12T15:09:35+00:00Added an answer on May 12, 2026 at 3:09 pm

    You really, really should not store “rounded” values in floating point variables. Floating point inaccuracy will ruin this – your 5.10 might become 5.099999999941892 simply because the implementation might not be able to store 5.10 exactly.

    As an alternative, read the whole number, multiply it with 100 and convert it to int (which will round it towards zero). That will keep your calculations accurate.

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

Sidebar

Related Questions

Is there an obvious way to do this that I'm missing? I'm just trying
This is pretty weird. I have my Profiler open and it obviously shows that
i have this problem that has been buggin me for the last hours. Lets
I already know the obvious answer to this question: just download <insert favorite windows
I have never worked with web services and rails, and obviously this is something
This obviously requires the source file to be under source control. I would ideally
This is obviously a stupid question. I am coding in Eclipse both on Mac
UPDATE: Obviously, you'd want to do this using templates or a base class rather
This is what I have so far: myArray.map!{ rand(max) } Obviously, however, sometimes the
What is the cause of this exception in ASP.NET? Obviously it is a viewstate

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.