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
The code above shows all three types of conversions we can use in our program. The first conversion from floating-point to integer is used when rounding is not considered. The conversion from floating-point to integer ignores truncates the decimal. The digits that come after the decimal point are ignored and the original number is not rounded during the process. If you want to round the floating point to an integer, all you have to do is to add 0.5 to the original value as shown above. This will round your floating-point 100% of the time.
1
+
The code above shows all three types of conversions we can use in our program. The first conversion from floating-point to integer is used when rounding is not considered. The conversion from floating-point to integer truncates the decimal. The digits that come after the decimal point are ignored and the original number is not rounded during the process. If you want to round the floating point to an integer, all you have to do is to add 0.5 to the original value as shown above. This will round your floating-point 100% of the time.
2
2
3
3
Converting strings to integer requires a similar method of using `| 0`. If the string doesn't start with a digit, the conversion will not work.
0 commit comments