PHP浮动小数点后两位:.00 [英] PHP float with 2 decimal places: .00

查看:102
本文介绍了PHP浮动小数点后两位:.00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我进行此类型转换时:

When I do this typecasting:

(float) '0.00';

我得到0.如何获取0.00并仍然具有浮点数据类型?

I get 0. How do I get 0.00 and still have the data type as a float?

推荐答案

浮点数没有00.00:浮点数是内部字符串( ="http://en.wikipedia.org/wiki/IEEE_floating_point" rel ="noreferrer"> IEEE754 )二进制格式,但浮点数相同.

A float isn't have 0 or 0.00 : those are different string representations of the internal (IEEE754) binary format but the float is the same.

如果要将浮点数表示为"0.00",则需要使用数字格式:

If you want to express your float as "0.00", you need to format it in a string, using number_format :

$numberAsString = number_format($numberAsFloat, 2);

这篇关于PHP浮动小数点后两位:.00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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