51
edits
Changes
m
variable name fix
i = (int) d;
The resulting value for a i is 0, as casting in C will truncate any positions after the decimal point -- no rounding will occur. The same is true for JavaScript. (In JavaScript, the bitwise operators such as | will trigger an integer conversion.)
To get proper rounding, following approach is often employed: