如何将a转换float为int舍入到下一个整数?例如,1.00001将转到2,而1.9999将转到2.
iOS*_*dev 63
float myFloat = 3.333
// for nearest integer rounded up (3.333 -> 4):
int result = (int)ceilf(myFloat );
// for nearest integer (3.4999 -> 3, 3.5 -> 4):
int result = (int)roundf(myFloat );
// for nearest integer rounded down (3.999 -> 3):
int result = (int)floor(myFloat);
// For just an integer value (for which you don't care about accuracy)
int result = (int)myFloat;
Run Code Online (Sandbox Code Playgroud)
Vla*_*mir 11
使用ceil函数:
int intValue = (int)ceil(yourValue);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27388 次 |
| 最近记录: |