PHP - 更改数字格式
PHP - change number format
我有这个代码:
<?php
if(isset($_POST['get_luna_inceput'])){
$ret =[];
$sch_luna_inceput = $_POST['get_luna_inceput'];
$sql = "SELECT
...";
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$ret[] =[$row['JUDET'], floatval($row['TOTAL'])];
}
}
}
echo json_encode($ret) ;
?>
我的代码 sql returns $row['TOTAL']
的数值格式为 (1523,45)。如何更改格式 (1.523,45)?我试过这个:$ret[] =[$row['JUDET'], number_format(floatval($row['TOTAL']),2,",",".")]
而不是 work.Thank 你!
$num = 1523.45;
echo number_format ( $num, 2, ",", "." );
执行 1.523,45
在你的情况下它将是
$ret[] = [ $row['JUDET'], number_format( $row['TOTAL']), 2, ",", ".") ];
希望对您有所帮助
我有这个代码:
<?php
if(isset($_POST['get_luna_inceput'])){
$ret =[];
$sch_luna_inceput = $_POST['get_luna_inceput'];
$sql = "SELECT
...";
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$ret[] =[$row['JUDET'], floatval($row['TOTAL'])];
}
}
}
echo json_encode($ret) ;
?>
我的代码 sql returns $row['TOTAL']
的数值格式为 (1523,45)。如何更改格式 (1.523,45)?我试过这个:$ret[] =[$row['JUDET'], number_format(floatval($row['TOTAL']),2,",",".")]
而不是 work.Thank 你!
$num = 1523.45;
echo number_format ( $num, 2, ",", "." );
执行 1.523,45
在你的情况下它将是
$ret[] = [ $row['JUDET'], number_format( $row['TOTAL']), 2, ",", ".") ];
希望对您有所帮助