I'm writing a program in C (NOT C ++) to convert money and I need to round U.S. currency to the nearest cent. How do I round money to the nearest cent?
Ex: $0.501 rounds to $0.50,
$0.505 rounds to $0.51,
$1.006 rounds to $1.01,
etc.
How do I round money to the nearest cent in C programming?
As far as I remember, C does not support a Currency data type and so you will have to use Float / Double variables to do this. You can use "round()" method by including %26lt;math.h%26gt; file.
A nice example at - http://www.codecogs.com/reference/math.h...
Reply:read each number as a char array.
compare last digit with five
if greater than five add 1 to previous character.
then print array n-1 element
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment