PHP中带小数的简单数学 [英] Simple math with decimals in PHP
本文介绍了PHP中带小数的简单数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这真杀了我!我从来没有遇到这么多麻烦,也无法弄清楚我在做什么错.
This is killing me! I've never had so much trouble and I can't figure out what I'm doing wrong here.
如果我有一个数字,说2.32,而我想用它做数学运算,那将是行不通的.最简单的例子:
If I have a number, say 2.32, and I want to do math with it it won't work out. The very simplest example:
$income = $commission; //Commission is 2.32, retrieved from XML
echo "income: $income<br>";
$income100 = $income*100;
echo "income100: $income100<br>";
我得到的结果是:
income: 2.32
income100: 200
如何在不改变小数的情况下准确地使用数学?
How can I use a decimal number accurately with math without it changing it?
非常感谢!
推荐答案
您需要以以下方式分配$income
来摆脱基础的SimpleXMLElement
:
You need to assign $income
in the following manner to get rid of the underlying SimpleXMLElement
:
$income = (float) $commission;
$x = simplexml_load_string("<a>2.4</a>");
echo $x * 100; // output: 200
这篇关于PHP中带小数的简单数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文