我在php中有一个简单的代码,想在比特币价值上增加3%:
</PHP
$price = "0.00001000"
$price_format = str_replace(".", "", $price);
echo ($price_format + ($price_format / 100 * 3)); // 1030
?>
返回我的代码: 1030
我需要退货单是: 0.0001030
有人知道我如何通过跟踪价格的房屋数量来执行此计算吗?
答案 0 :(得分:1)
在乘以3%时,可以使用number_format
以保持小数位不变。将价格乘以1.03(3%),并指定8个小数位。
<?php
$price = 0.00001000;
$new_price = number_format($price * 1.03, 8);
echo $new_price;
以下是指向number_format
的链接以获取更多信息:
https://www.php.net/manual/en/function.number-format.php