[iOS] float to int 四捨五入

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;  

Polo

Having being a full stack engineer. His interests in Node.js, ARM mbed, IoT solutions, iOS Contact us : [email protected]

ALL RIGHTS RESERVED. COPYRIGHT © 2016. Designed and Coded by Makee.io