比方说3.1415926,我现在想传给后台的是3.14,类型是必须是float类型,该怎么样做?还有即便通过运算得到了3.14,然后我要是按float传过去,是不是本质上传的还是3.1400000?
小伙看你根骨奇佳,潜力无限,来学PHP伐。
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
The double type is more accurate. You can also try the NSDecimalNumber class
Use floor 函数即可:double re = floor(numFloat*100) / 100;
floor
double re = floor(numFloat*100) / 100;
You can use toFixed(2) to retain two decimal places
.2f is generally acceptable
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
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