I've tried using DECIMAL with (2,2) but it won't let me use this.
I simply want to store a number, for example 7.50 or 10.50. I need to keep both numbers after the decimal though but when I refresh the database it resets the values to 0.99. Any suggestions?
MySQL DECIMAL storageMySQL assigns the storage for integer and fractional parts separately. MySQL uses binary format to store the DECIMAL values. It packs 9 digits into 4 bytes. For example, DECIMAL(19,9) has 9 digits for the fractional part and 19-9 = 10 digits for integer part.
The database server uses one byte of disk storage to store two digits of a decimal number, plus an additional byte to store the exponent and sign, with the first byte representing a sign bit and a 7-bit exponent in excess-65 format. The rest of the bytes express the mantissa as base-100 digits.
MySQL FORMAT() function MySQL FORMAT() converts a number to a format like '#,###,###. ##' which is rounded upto the number of decimal places specified (in the second argument) and returns the result as a string.
The first parameter of the DECIMAL
declaration is the total digits. You probably want to use DECIMAL (4, 2)
. This allows for up to two digits before the decimal and two after.
Documentation: https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html
The syntax is DECIMAL(M,D)
M - total length
D - digits right of the decimal point
http://dev.mysql.com/doc/refman/5.6/en/fixed-point-types.html
The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.6 are as follows:
M is the maximum number of digits (the precision). It has a range of 1 to 65. (Older versions of MySQL permitted a range of 1 to 254.)
D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.
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