In: Computer Science
Explain the difference between truncation and rounding.How can one operation be made to perform the function of the other?
Truncation: In this case, the remaining digits after the decimal
is chopped off, thus for example 23.49 if chopped or truncated will
be made to just 23.
Rounding: In this case, we have to round or made the given number
to the closest number as mentioned or said so while rounding. Like
if we have to round the decimal number 23.4589 to 2 decimal digits
then it will be rounded to 23.46 as the digit after the 45 is 8 so
45 will be rounded to 46.
For rounding and truncation to work same, we need to round a
number to the nearest integer and if the decimal digits after the
decimal are less than 5. Then the truncation and rounding will work
the same.
Like if want to round 23.45 to the nearest integer and truncate
23.45.
So both of them will make it 23.
That was a nice
question to answer
Friend, If you have any doubts in understanding do let me know in
the comment section. I will be happy to help you further.
Thanks