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.
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.
It has a range of 1 to 65. D is the number of digits to the right of the decimal point (the scale).
The ROUND() function rounds a number to a specified number of decimal places.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With