C++ Programming

To calculate a mortgage payment, what types would you use for the rate, principal, and payment? Explain why you selected each type.

We can use float or double. Float takes 4 bytes of memory whereas double takes 8 bytes of memory. Float has a lower precision and it is used to store decimal numbers with fewer digits. Double has a higher precision and stores decimal numbers with more digits. Double has at most twice the precision. Float has 7 decimal digits of precision whereas double has 15 decimal digits of precision. So if precision is not the requirement, we can use float to save memory.  

We can use the rate as a float like that: 5.69% per year. The principal like to float  that,  $1000.784. The payment like double  that: $ 15000.147825.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments