English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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.

2007-02-04 07:43:39 · 2 answers · asked by anonms420 1 in Computers & Internet Programming & Design

I'm a begginer at programming, so please give me simple solutions that are easy to understand, as I do not know much about C programming.

2007-02-04 08:10:51 · update #1

2 answers

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

2007-02-04 07:56:40 · answer #1 · answered by iyiogrenci 6 · 0 0

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 file.

A nice example at - http://www.codecogs.com/reference/math.h/round.php?alias=round

2007-02-04 16:01:49 · answer #2 · answered by Aryan 2 · 0 0

fedest.com, questions and answers