1

i'm developing a PHP application and i have one problem when i use HTML text inputs, and this is the first time where i deal with this case. When i try to insert a float value as 34.4 in HTML text input to put it in MySQL DB, but when i go to my DB i find the value 35. I don't know why this value is rounded, i do not use any function like ceil. If someone can help me i'll be so thankful.

Abdelilah Aassou
  • 148
  • 3
  • 15

3 Answers3

1

If you are working with decimal, the default is DECIMAL(10, 0), you should specify the precision and scale, for example:

DECIMAL(10, 4)

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.7 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.

Reference: http://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html

Also, check this answer: How do I interpret precision and scale of a number in a database?

Community
  • 1
  • 1
cch
  • 3,336
  • 8
  • 33
  • 61
0

Set column type to float in Mysql

MCurbelo
  • 4,097
  • 2
  • 26
  • 21
0

The problem was in DB column type, it was DECIMAL(10,0) for this reason the MySQL rounded the float number to an INT number.

Abdelilah Aassou
  • 148
  • 3
  • 15