如何阻止PHP更改所有小数分隔符?

时间:2011-11-16 15:26:57

标签: php mysql

我的(MySQL)表格中的货币值设置为十进制(10,2),小数以逗号分隔。然而,每当我查询它们时,php会将所有逗号都转换为句点并使我的结果无效。我可以阻止这样做吗?它会影响我的SELECT和我的INSERT / UPDATE。

当我选择时,例如,123,00 php将其变为12300.00;相同的插入数字:我插入123,00但表中的值再次变为12300,00。有没有办法让逗号成为默认的小数分隔符?

2 个答案:

答案 0 :(得分:2)

你看过了吗? http://php.net/manual/en/function.money-format.php

$number = 1234.56;

// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";

答案 1 :(得分:0)

对于PHP部分,这可能对我有帮助

<?php

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>

这应该可以为您提供如何从PHP代码中获取正确输出的线索。 不关心数据库如何存储您的数字,也不关心PHP如何在内部进行数据存储。 使用number_format获得所需的输出。

有关详情,请参阅PHP: number-format