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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:36:57+00:00 2026-06-07T12:36:57+00:00

I am trying to multiply two float s as follows: float number1 = 321.12;

  • 0

I am trying to multiply two floats as follows:

float number1 = 321.12;
float number2 = 345.34;
float rexsult = number1 * number2;

The result I want to see is 110895.582, but when I run the code it just gives me 110896. Most of the time I’m having this issue. Any calculator gives me the exact result with all decimals. How can I achive that result?

edit : It’s C code. I’m using XCode iOS simulator.

  • 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-07T12:36:59+00:00Added an answer on June 7, 2026 at 12:36 pm

    There’s a lot of rounding going on.

    float a = 321.12; // this number will be rounded
    float b = 345.34; // this number will also be rounded
    float r = a * b;  // and this number will be rounded too
    printf("%.15f\n", r);
    

    I get 110895.578125000000000 after the three separate roundings.

    1. If you want more than 6 decimal digits’ worth of precision, you will have to use double and not float. (Note that I said “decimal digits’ worth”, because you don’t get decimal digits, you get binary.) As it stands, 1/2 ULP of error (a worst-case bound for a perfectly rounded result) is about 0.004.

    2. If you want exactly rounded decimal numbers, you will have to use a specialized decimal library for such a task. A double has more than enough precision for scientists, but if you work with money everything has to be 100% exact. No floating point numbers for money.

    Unlike integers, floating point numbers take some real work before you can get accustomed to their pitfalls. See “What Every Computer Scientist Should Know About Floating-Point Arithmetic“, which is the classic introduction to the topic.

    Edit: Actually, I’m not sure that the code rounds three times. It might round five times, since the constants for a and b might be rounded first to double-precision and then to single-precision when they are stored. But I don’t know the rules of this part of C very well.

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

Sidebar

Related Questions

I'm trying to multiply two arrays without using numpy. But, I receive an error
I'm trying to multiply two matrices using vecLibs' cblas: #include <stdlib.h> #include <string.h> #include
I am trying to overload the * operator in order to multiply two objects
Am new to this guys need your help! Am trying to multiply two field
I'm trying to get two divs to float to opposite sides of the page,
I am trying to multiply two strings, but I am getting the wrong answer.
I am trying to multiply two 3x3 matrices. The first 2 numbers in the
Im trying to multiply two 16 bit numbers with the following NASM codes: mov
I'm trying out a very simple program in LAZARUS to multiply two text box
I am trying to multiply two vectors together where each element of one vector

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.