格式的千位数字与两个小数点插入数据库


Format for thousands number with two decimal places insert into database

我有值1000,我希望它是小数点后两位。我所做的就是使用数字格式函数。

number_format(1000,2);

输出是这样的1,000.00。然而,我不能插入1,000值与,符号到我的db表类型十进制(6,2)。有没有办法,我可以把我的1000值和小数点后两位一起插入。或者我需要更改我的表类型?

存储为DECIMAL,并使用FORMAT:

CREATE TABLE tab(col DECIMAL(6,2) );
INSERT INTO tab VALUES (10), (67), (1000), (1006.2);
SELECT FORMAT(col, 2) AS result
FROM tab;

SqlFiddleDemo

输出:

╔══════════╗
║  result  ║
╠══════════╣
║ 10.00    ║
║ 67.00    ║
║ 1,000.00 ║
║ 1,006.20 ║
╚══════════╝

尝试使用bcadd()

$a = bcadd("100","0","2");
echo $a;// output is 100.00

更多参考