Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql float data field not accepting every float number

Tags:

mysql

I have a float data field :

`total` float(20,2) unsigned NOT NULL,

I want to insert a float number like : "815032.68" but it's not accepted and the number is rounded to 815032.69. why?

like image 912
Murat Avatar asked Jun 18 '26 06:06

Murat


1 Answers

Use a fixed-point data type

`total` DECIMAL(20,2) unsigned NOT NULL

The DECIMAL and NUMERIC types store exact numeric data values. These types are used when it is important to preserve exact precision, for example with monetary data.

MySQL Doc

Floating-point data types can only store approximate numbers.

like image 50
juergen d Avatar answered Jun 20 '26 00:06

juergen d



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!