我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

在PHP中正确格式化数字

I am trying to format 2176 as 21.76 in php

I have this code: $Payment->amount equals 2176 in this example.

$<?php echo number_format($Payment->amount,'2')/100; ?>

I get 0.02 Why?

number_format($Payment->amount,'2') gives you string '2', then you divide it by 100, so the result is 0.02.

It should be:

$<?php echo number_format($Payment->amount / 100, 2); ?>

You need to do the division before you format the number:

$<?php echo number_format($Payment->amount/100,'2'); ?>

近期文章

  • 在终端输入数据后没反应
  • VS中 unable to start debugging
  • 输出一直是1,哪里出问题了?
  • python使用opencv创建滑动条时闪退
  • 有赏,最好可以解决opencv,pycharm anaconda
  • vue的常用表达式用法
  • 为啥我这个三角形的程序怎么运行都是无法构成三角形
  • 数据结构设计里面的一种Getelem
  • php - >在级联中使用的运算符
  • django4.0断点无效,网上方法试过了
  • unity输入文本框在输入时出现错误
  • 求解!IDEA运行报错:Abnormal build process termination:
  • dev c++6.3运行不出来
  • 数据结构设计程序的过程
  • 关于sql存储过程的输入参数
  • 为什么pyinstaller不能升级到4.3?
  • 问题遇到的现象:之前打开软件正常运行,电脑系统WIN11.今天电脑开机开软件提示“无法在虚拟机运行,如何解决?
  • rocketmq发送消息报错
  • too long
  • 电脑自动修复不了,一直无限循环

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华