PHP - 更改数字格式 [英] PHP - change number format

查看:57
本文介绍了PHP - 更改数字格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

<?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 以数字格式 (1523,45) 返回 $row['TOTAL'] 的值.如何更改格式 (1.523,45)?我试过这个: $ret[] =[$row['JUDET'], number_format(floatval($row['TOTAL']),2,",",".")] 和不行.谢谢!

My code sql returns values for $row['TOTAL'] in number format (1523,45). How can I change in format (1.523,45)? I tried this: $ret[] =[$row['JUDET'], number_format(floatval($row['TOTAL']),2,",",".")] and not work.Thank you!

推荐答案

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

执行 1.523,45

executes 1.523,45

在你的情况下是

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

希望有帮助

这篇关于PHP - 更改数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆