Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in c# Math.floor may be used to round a number to a specific decimal place. The

ID: 3657552 • Letter: I

Question

in c# Math.floor may be used to round a number to a specific decimal place. The statement y = Math.floor( x * 10 + 0.5 ) / 10; rounds x to the tenths position (i.e., the ?rst position to the right of the decimal point). The statement y = Math.floor( x * 100 + 0.5 ) / 100; rounds x to the hundredths position (i.e., the second position to the right of the decimal point). Write an application that de?nes four methods for rounding a number x in various ways: a) roundToInteger( number ) b) roundToTenths( number ) c) roundToHundredths( number ) d) roundToThousandths( number ) For each value read, your program should display the original value, the number rounded to the nearest integer, the number rounded to the nearest tenth, the number rounded to the nearest hundredth and the number rounded to the nearest thousandth.

Explanation / Answer

RoundToInteger( number )

{ printf("%f",number);

printf("%f",Math.floor(number + 0.5 ));

}


RoundToTenths( number )

{

printf("%f",Math.Floor( number * 10 + 0.5 ) / 10);

}


RoundToHundredths( number )

{

printf("%f",Math.Floor( number * 100 + 0.5 ) / 100);

}


RoundToThousandths( number )

{

printf("%f",Math.Floor( number * 1000 + 0.5 ) / 1000);

}