Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL: DECIMAL with accuracy of 10 digits after the comma

Tags:

mysql

decimal

In MySQL I have a DECIMAL field set to 10,10. However, whenever I enter a new value, it shows 0.9999999999. What would I need to change to accept any number with an accuracy of 10 digits after the comma? It does work with 10,6 for some reason.

PS: I want to insert exchange rates.

like image 436
Frank Vilea Avatar asked Jun 29 '11 18:06

Frank Vilea


People also ask

How do I limit decimal places in SQL?

If you'd like to round a floating-point number to a specific number of decimal places in SQL, use the ROUND function. The first argument of this function is the column whose values you want to round; the second argument is optional and denotes the number of places to which you want to round.

What is the range of decimal in MySQL?

It has a range of 1 to 65. D is the number of digits to the right of the decimal point (the scale).

How do I get two decimal places in MySQL?

The ROUND() function rounds a number to a specified number of decimal places.


2 Answers

The first number is the total number of digits to store, the second one is the number of digits on the fractional part. So DECIMAL (10, 10) is only for 10 fractional digits. You can use something like DECIMAL (20, 10) to allow 10 digits on both the integral and fractional parts.

like image 119
Xint0 Avatar answered Sep 23 '22 07:09

Xint0


DECIMAL(10,10) means there's no decimal places left for values before the decimal place. You're limiting things to always being x < 1.

It's DECIMAL(total number of digits, digits after the decimal). With 10,10, you're saying "10 digits after the decimal", leaving 10-10 = 0 before the decimal. This means you cannot store 1, and 0.9999999999 is the nearest value that fits within your field definition.

like image 45
Marc B Avatar answered Sep 22 '22 07:09

Marc B