krdev krdev - 5 months ago 7
MySQL Question

Wy decimal numbers are not stored as expected in mysql

I'm trying to save numbers in decimal data type filed formated (10,4), but it's not stored as expected ie. 13850 changed to 13.0000 any help.
this is my code:

$c_price = $unit_price*$rate;
$expense->c_price = number_format($c_price, 4);
$expense->c_total = number_format($quantity*$c_price, 4);


Here c_price and c_total values are changed.

Answer

Increase the length of digits:

(19,4)

it will work.