Hey everyone,(adsbygoogle = window.adsbygoogle || []).push({});

I'm writing a simple program to calculate the monthly payment amount for a loan given a principal, down payment, finance term, and interest rate. The monthly payment needs to be reported to the userrounded to two decimal placesafter they have entered all the required information. The assignment instructions specify that the monthly payment should beroundedto two decimal places, not truncated, floored, ceiled (?), etc.

To accomplish this, I have used the conversion specification in the printf statement to specify that the monthly payment should be printed to two decimal places:

"printf("The monthly payment amount is: %.2lf", downPayment);"

Does this method round properly, or does it just truncate? Will it produce the same results as multiplying the monthly payment by 100, using the round function from math.h to round the result, and then dividing by 100?

Thanks!

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Rounding in C

**Physics Forums | Science Articles, Homework Help, Discussion**