0

I am trying to get MySQL decimal field types to work nice and I just can't figure it out. I send a $_POST['price'] field to a decimal field, for example 3.45, and it always stores it as 3.00.

What would I be doing wrong for it to not store the decimals?

Found the solution: PDO::PARAM for type decimal?

PDO has not decimal storing type, seems like something massive to miss out. Need to store it as a string not a numeric number.

4

1 回答 1

0

floatval()$_POST['price']变量从字符串转换为浮点时使用。该值应该存储在您的数据库中。

不过要小心!由于可能的舍入误差,浮点运算在计算价格时并不是那么好。在处理价格时,我通常使用整数运算,然后手动输入小数点。

所以在你的例子中我会存储345代表$3.45

于 2013-07-19T19:39:16.857 回答