You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Truncation during conversion from floating point to integer types is non-obvious behavior that frequently causes confusion for beginners who expect rounding to occur. Example:
float x = 2.9;
int y = x; // 2
Rounding could be achieved by adding 0.5 during the conversion:
float x = 2.9;
int y = x + 0.5; // 3
or the use of round():
float x = 2.9;
int y = round(x); // 3
This should be documented in the float and double reference pages.
Truncation during conversion from floating point to integer types is non-obvious behavior that frequently causes confusion for beginners who expect rounding to occur. Example:
Rounding could be achieved by adding 0.5 during the conversion:
or the use of
round()
:This should be documented in the float and double reference pages.
Originally suggested by PaulStoffregen at arduino/Arduino#8751 (comment)
The text was updated successfully, but these errors were encountered: