PHP:将数字四舍五入成十六进制数字 [英] PHP: rounding a number into 16 decimal digits
问题描述
您好,我正在尝试将一个数字四舍五入到<十六进制数字中,但它只显示并且不会四舍五入到十四进制数字。
这是我的尝试:
<?php
$ num = 0.16346153846153846;
$ round = number_format((float)$ num,17,'。','');
echo $ round * -1;
?>
输出:
0.16346153846154
预期产量:
0.1634615384615385
我知道浮点只有14个十进制数字。是否有任何其他的方式来解决十六进制数字?
运行。在大多数平台上,16位通常是最大
的值,较大的值只给出无意义的或虚构的
数字:
ini_set(precision,16);
请参阅改变精度级别的浮点变量
Hi I'm trying to rounding a number into the 16 decimal digits but it only show and doesn't round up till 14 decimal digit.
Here's my attempt:
<?php
$num= 0.16346153846153846;
$round = number_format((float)$num, 17, '.', '');
echo $round * -1;
?>
OUTPUT:
-0.16346153846154
EXPECTED OUTPUT:
0.1634615384615385
I know that float is only 14 decimal digits. Is there any other way around for the 16 decimal digits?
You can set this parameters at run-time. 16 digits is usually the maximum value on most platforms, larger values giving only meaningless or "fictional" digits:
ini_set("precision", "16");
See Changing precision level floating-point variables
这篇关于PHP:将数字四舍五入成十六进制数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!