如何将数字格式化为仅保留小数点后两位? [英] How do I format numbers to have only two decimal places?

查看:128
本文介绍了如何将数字格式化为仅保留小数点后两位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望实数是例如12.92,而不是12.9241.可以那样做吗?

I want that real numbers would be for example 12.92, but not 12.9241. Is it possible to do like that?

推荐答案

在PHP中,尝试 number_format :

$n = 1234.5678;

// Two decimal places, using '.' for the decimal separator
// and ',' for the thousands separator.
$formatted = number_format($n, 2, '.', ',');
// 1,234.57

这篇关于如何将数字格式化为仅保留小数点后两位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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