简体   繁体   English

PHP-更改数字格式

[英]PHP - change number format

I have this code: 我有以下代码:

<?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) ;
?>

My code sql returns values for $row['TOTAL'] in number format (1523,45). 我的代码sql以数字格式(1523,45)返回$row['TOTAL']的值。 How can I change in format (1.523,45)? 如何更改格式(1.523,45)? I tried this: $ret[] =[$row['JUDET'], number_format(floatval($row['TOTAL']),2,",",".")] and not work.Thank you! 我试过了: $ret[] =[$row['JUDET'], number_format(floatval($row['TOTAL']),2,",",".")]无效。谢谢!

$num = 1523.45;
echo number_format ( $num, 2, ",", "." );

executes 1.523,45 执行1.523,45

in your case it will be 在你的情况下

$ret[] = [ $row['JUDET'], number_format( $row['TOTAL']), 2, ",", ".") ];

Hope it helped 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM