PHP中的JS:something.toFixed()的确切含义是什么? [英] What is the exact equivalent of JS: something.toFixed() in PHP?

查看:93
本文介绍了PHP中的JS:something.toFixed()的确切含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在javascript中有a.toFixed(3);("a"等于2.4232),那么在php中检索它的确切等效命令是什么?我进行了搜索,但没有在答案后附加正确的解释.

If I have a.toFixed(3); in javascript ('a' being equal to 2.4232) what is the exact equivalent command in php to retrieve that? I searched for it but found no proper explanation appended to the answers.

推荐答案

我发现sprintfnumber_format都将数字四舍五入,所以我用了这个:

I found that sprintf and number_format both round the number, so i used this:

$number = 2.4232;
$decimals = 3;
$expo = pow(10,$decimals);
$number = intval($number*$expo)/$expo; //  = 2423/100

这篇关于PHP中的JS:something.toFixed()的确切含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆