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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:30:15+00:00 2026-06-14T17:30:15+00:00

Here is a code I wrote: #include <stdio.h> #include <stdlib.h> int main() { double

  • 0

Here is a code I wrote:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    double num;
    int tmp;
    printf("enter a number!\n");
    scanf("%lf",&num);
    tmp=num*10000;
    printf(" temp=%d\n",tmp);

    return 0; 
}

When I enter the number 1441.1441 the result i’m getting is 14411440 instead of
14411441 which is obviously the correct result after multiplying my input number by 10000. Can someone help me figure out this problem?

  • 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-14T17:30:17+00:00Added an answer on June 14, 2026 at 5:30 pm

    Since the vast majority of real numbers cannot actually be represented exactly, you’ll probably find that 1441.1441 is actually stored as something like 1441.14409999_blah_blah_blah. You can find that out by inserting:

    printf ("%.50lf\n", num);
    

    immediately after the scanf and seeing (trailing zeroes removed):

    1441.14409999999998035491444170475006103515625
    

    Now that’s actually the correct (ie, closest) value based on your input. The next highest number from there gives you:

    1441.144100000000207728589884936809539794921875
    

    The error with the first value is:

    0.00000000000001964508555829524993896484375
                   ^ ~ 2 x 10^-14
    

    while the error with the second is:

    0.000000000000207728589884936809539794921875
                  ^ ~ 2 x 10^-13
    

    and you can see the latter error is about 10 times as much.

    When you multiply that by 10000 and try to shoehorn it into an int, it gets rounded down (truncated). That’s because the (C11) standard has this to say in 6.3.1.4:

    When a finite value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero).

    One thing you can try is to change your shoehorning line into:

    tmp = num * 10000 + 0.5;
    

    which effectively turns the truncation into a rounding operation. I think that will work for all cases but you may want to test it (and keep an eye on it) just in case.

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

Sidebar

Related Questions

Here is my code: #include <stdio.h> #include <stdlib.h> int main(){ int n=10; char *s=
Here is my code: #include<stdio.h> #include<stdlib.h> #include<sys/stat.h> #include<sys/types.h> #include<fcntl.h> #include<unistd.h> #include<errno.h> int main(int argc,char
I wrote a simple url parser using strtok(). here's the code #include <stdio.h> #include
I'm trying to write a video using opencv's VideoWriter. Here's code: int main() {
#include <stdio.h> #include <stdlib.h> #include <string.h> struct stCrimeArchive { char id_student[10]; int id_document; char
Here is the code i wrote,when i execute the code,the terminal didn't output anything
i added sharekitkit my project. And wrote code like here : SHKItem *item =
here is a small peice off code that i wrote. But I am not
So, here's the problem. I wrote a code that opens a div based on
Alright, here I am again trying to write code from scratch and I can't

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.