ios - float 保留两位小数
伊谢尔伦
伊谢尔伦 2017-04-18 09:57:04
0
6
1299

比方说3.1415926,我现在想传给后台的是3.14,类型是必须是float类型,该怎么样做?
还有即便通过运算得到了3.14,然后我要是按float传过去,是不是本质上传的还是3.1400000?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(6)
刘奇

It should be possible to use string formatting, because what is received in the background is also a string type, not a float type, just use .2f directly

伊谢尔伦

Why are all strings transmitted from the front to the backend? Float doesn’t have any number of decimal places, or bigdecimal

PHPzhong

The double type is more accurate. You can also try the NSDecimalNumber class

迷茫

Use floor 函数即可:
double re = floor(numFloat*100) / 100;

刘奇

You can use toFixed(2) to retain two decimal places

伊谢尔伦

.2f is generally acceptable

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template