The problem occurs when I do a division operation. I would like to know who to truncate a number with a decimal point into a whole number such as 2, 4, 67.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It truncates automatically is you assign value to “int” variable:
Or you can cast like this:
This truncates it even if c is defined as float or double.
Usually truncation is not the best (depends what you want to achieve of course). Usually result is rounded like this:
is more intelligent because rounds result properly. If you use linux, you can easily get reference with “man round” about exact data types etc.