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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:15:52+00:00 2026-06-09T10:15:52+00:00

Ok so I have a weird issue where I am running a query that

  • 0

Ok so I have a weird issue where I am running a query that in the select it is taking the result and multiplying that by 2000 i.e. 0.0025 * 2000 and giving me 4.9999888419121 or something when it should be 5. I have seen that there are issues with this but I have yet to find if there was a solution. I thought that math was like a basic computing function why would it fail in such a simple request as multiplication.

I am not sure that there is a fix for this, I really have been researching it but I figure that if anyone knew of one it would be here.

thanks again

example:

SELECT (table.rate * 2000) as per_ton ...

I have tried the + 0.0000 tricks and all without luck

  • 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-09T10:15:53+00:00Added an answer on June 9, 2026 at 10:15 am

    This issue is not unique to MySQL. It’s a common issue with IEEE floating point representation, which store approximations of decimal values. (The IEEE floating point types store exact base 2 representations.)

    So, it’s not a “failure” of a multiplication operation. The value you stored for rate was (apparently) decimal value of .0025. This value can’t be represented EXACTLY in an IEEE floating point, so what gets stored is the closest possible approximation. When that approximate value is multiplied by 2000, the result is also an approximate value, which is then being converted back to decimal for display.

    The “fix” is to use the DECIMAL datatype, rather than the floating point types, and have the multiplication operation be performed using “big decimal” operations, rather than floating point operations.

    You can attempt to have that approximation reversed, by converting it back to decimal of specified precision, before you do the multiplication:

    SELECT (CAST(table.rate AS DECIMAL(18,4) * 2000) AS per_ton ...
    

    Or, you can try using the ROUND() function to trim off the digits of precision you don’t need, e.g.

    SELECT ROUND((table.rate * 2000),4) AS per_ton ...
    

    That will get the result rounded up to 5.0000

    The real “fix” though, is to define your columns with DECIMAL datatype, and AVOID using floating point columns at all.

    This behavior of floating point values is well documented, albeit, at the end of the manual:

    http://dev.mysql.com/doc/refman/5.1/en/problems-with-float.html

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

Sidebar

Related Questions

I'm running a weird issue here. I have code that makes jquery ajax calls
I have an weird issue, I am running the following SQL statement: SELECT *
I have extended SimpleCursorAdapter and am running into a weird issue with bindView, which
I have a weird issue. I have some icons that are being built based
I have this weird crash that only happens when running the app on the
I have a Custom Listview but i'm running into a weird issue when I
Having a weird issue. I'm new to Macs and have a windows VM that
I have this very weird issue that I cant really get why it's not
So I have a very weird issue in which that when I run my
I have a weird issue that only seems to be affecting IE 7. The

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.