2

I have single record on a table. So on MySQL when

 select myamount from table 1  -- returns amount 420.67

But when i do MySQL as

 select sum(myamount) from table 1 -- returns amount 420.8699951171875

should n't it return same amount 420.67 since I have only one record? and how to get amount 420.67 if SUM used.

Any help is appreciated and yes myamount datatype is float.

1

1 Answer 1

1

Float variables are stored in "scientific notation" (the 2,4E+04 format, which is the same as 2,4*10^4). But to make it even worse, it is also stored in binary. When calculating things with numbers stored as float, you may get a bit strange results because of this.

This video by Computerphile describes the problem very nicely.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.