round
uint8_t round(uint8_t x)int8 round(int8 x)
int round(int x)
float round(float x)
Description
Returns x rounded to the nearest integer, with halfway cases rounded away from zero.
For integer types the value is returned unchanged.
The return type matches the input type.
Parameter
- x - A numeric value (uint8_t, int8, int or float).
Returns
The rounded value of x, with the same type as the input.
Example
void main()
{
float a = round(3.5); // a = 4.0
float b = round(3.4); // b = 3.0
float c = round(-2.5); // c = -3.0
int d = round(7); // d = 7
}