Question: Problem 4 . 2 ( 1 0 pts ) : Given that floating - point numbers are an approximation anyway, we should devise a way
Problem pts: Given that floatingpoint numbers are an approximation anyway, we should devise a way
to round these numbers to two decimal places, as that will be plenty accurate for our purposes. Define and
implement a function named exactly roundtotwo, that takes a decimal number and returns that number
rounded to only two decimal places. Your function should round using the Half RoundUp method, so a number
such as would round to for zero decimal places, for one, for two, and so on
To receive any credit for this problem, you are not allowed to use the Python builtin round function!
Hint:
The modulus operator and the floor division operator are handy tools when working with values that are better split into
their remainder and whole divisor portions. While it might be mathematically silly to divide or modulate by one when using
integers, this is a very helpful technique when working with floats!
evaluates to
evaluates to
In Module lectures, we presented the technique to round for zero decimal places. If we want to use the same technique
to round to one decimal place, we need to first shift the decimal point one place to the right value apply the
technique to round, and shift the decimal point back to the left value value to get the desired result. This
approach can be extended to round to two decimal places!
Examples:
roundtotwo
roundtotwo
roundtotwo
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
