Sat*_*nix 10 php floating-point mysqli floating-accuracy floating-point-precision
我必须将一些项目的价格放在mysql表中.在创建我正在使用的表时,DECIMAL(10,2)因为我在逗号后不需要超过2位数(例如:123,45将被接受作为输入,但123,456将被舍入为123,45与PHP).
第一个问题:使用DECIMAL(10,2),如何知道逗号之前可以存储多少个数字?我知道它不是10,因为10只是Mysql在使用这些数字进行数学运算时所使用的精度:那么数字本身的长度是指定的吗?
第二个问题:我使用PHP来舍入用户输入以适应数据类型(逗号后面带有2个数字的浮点数).我该如何使用它mysqli->bind_param来插入这些数据?我应该使用哪些数据类型(来自文档)bind_param(可能:为什么)?
Character Description
i corresponding variable has type integer
d corresponding variable has type double
s corresponding variable has type string
b corresponding variable is a blob and will be sent in packets
Run Code Online (Sandbox Code Playgroud)