php - PHP在做数学减法之前用前导点格式化千数?
问题描述
我正在尝试用千分之一的两个数字进行减法运算,其格式如下所示,但我无法弄清楚使用number_format()
函数来获取thousand
没有前导"dot"
作为分隔符的显示,并按如下方式进行数学运算。
得到结果 0,032 而不是 32
<?php
$a = "1.545"; // how to format this to 1545? (here could be 0, 1, 6, 10, 54, 389, 600, 1600, 5000)
$b = "1.513"; // how to format this to 1545? (here could be 0, 1, 6, 10, 54, 389, 600, 1600, 5000)
$c = $a- $b; // subtraction
echo $c; // result 0,032 instad of just 32
?>
如何将 1.545 格式化为 1545 然后进行减法?
解决方案
得到它的工作!结果 32
<?php
$a = "1.545";
$b = "1.513";
$c = intval(str_replace('.','',$a))-intval(str_replace('.','',$b));
echo $c;
?>
推荐阅读
- r - 数据透视表对参考的列进行求和和计数
- css - 水平数据.GUI
- android-studio - Flutter中pop时如何清空页面
- react-native - 如何将 Realm 数据库导出到 React Native 中的文件?
- node.js - 如何从角度组件调用 express api 端点中的搜索函数?
- mysql - 具有过滤功能的 AVG 函数中的 MySQL 精度
- php - 我可以通过关系在一个查询中获得所有需要的数据吗?
- sql-server - 在 SQL Server 中处理易混淆的字符
- react-native - 导航参数未定义
- class - Flutter TextFormField Validation使用构造函数调用一页错误