MySQL Forums
Forum List  »  Newbie

Re: Comparison Between Floating Point Types
Posted by: Rick James
Date: November 27, 2012 08:37PM

Do not use (10,5) on FLOAT or DOUBLE. That unnecessarily rounds the values to 5 decimal places as you INSERT the value.

Suggest you remove that and rerun your test. You will have new questions. Let me see if I can answer some of them...

FLOAT gives you about 7 "significant digits" of precision. That is, FLOAT can store
314159300000.0 or 3.141593 or 0.0000314159300000
(except that they won't print trailing zeros; instead it will be junk.)

DOUBLE give you about 16 significant digits:
+-------------------+
| ATAN(1)*4         |
+-------------------+
| 3.141592653589793 |
+-------------------+

DECIMAL(M,N) lets you restrict the storage to N digits after the decimal point and M-N digits before. M can be up to 64 (or maybe 63?).

FLOAT occupies 4 bytes; DOUBLE, 8; DECIMAL--depends on M and N.

FLOAT allows values between about 10**-38 and 10**38; DOUBLE has a much wider range.

Use FLOAT or DOUBLE for "scientific" stuff; use DECIMAL for money.

Use the FORMAT() function for controlling where to round off output:
+----------------------+
| FORMAT(ATAN(1)*4, 4) |
+----------------------+
| 3.1416               |
+----------------------+

Options: ReplyQuote


Subject
Written By
Posted
Re: Comparison Between Floating Point Types
November 27, 2012 08:37PM


Sorry, you can't reply to this topic. It has been closed.

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.