Bug #111142 Float calculate result changes when adding brakets
| Submitted: | 24 May 2023 15:03 | Modified: | 25 May 2023 14:21 |
|---|---|---|---|
| Reporter: | Siyang Weng | Email Updates: | |
| Status: | Not a Bug | Impact on me: | |
| Category: | MySQL Server | Severity: | S3 (Non-critical) |
| Version: | 8.0.18 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | bug;float;calculation | ||
[24 May 2023 15:03]
Siyang Weng
[25 May 2023 12:31]
MySQL Verification Team
Hi MR. Weng, Thank you for your bug report. However, it is not a bug. First of all, you are using an ancient release of MySQL. Current release is 8.0.33. But, the crux of your problem is that your data domain is DECIMAL, while you are using the constants from the FLOAT / DOUBLE domain. Try using just 0.001 ....... Also, leave the blanks between the numbers and operations in your arithmetics ........ Not a bug.
[25 May 2023 13:30]
Siyang Weng
Thanks for your reply and advice! So is it expected that adding brakets to FLOAT / DOUBLE expression may change its result? If so, I will avoid using float and double in the future.
[25 May 2023 13:37]
MySQL Verification Team
Hi, You may use FLOAT and DOUBLE as much as you wish, but don't mix them with DECIMAL. Those are two totally different data types. Also, write expressions differently. Instead of: a=0.001+1e-1-1e-1; do the following: a=0.001 + 1e-1 - 1e-1; // when 'a' is FLOAT or DOUBLE and a=0.001 + 0.1 - 0.1; // when 'a' is DECIMAL Simply, DECIMAL do not use scientific notation. This is all described in our Reference Manual.
[25 May 2023 14:21]
Siyang Weng
Got it. Thanks a lot!
[25 May 2023 14:25]
MySQL Verification Team
You are truly welcome .....
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.054 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.