Hello.
I`m a beginner to JAVA.
Have an exercise to write a program that converts money sum to number of bills and coins and prints it. f.e.:
47.63 =
4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickles
3 pennies
I wrote it in different ways but the MONEY value seems to lose precision after arithmetic operations on it.
whether I do it like that :
DOLLAR_100 = (int) MONEY / 100;
MONEY = MONEY % 100;
or even without changing the value of money:
DOLLAR_100 = (int) MONEY /100;
DOLLAR_50 = (int) MONEY %100 / 50;
It loses precision as seen in the images.
Please help,
Thanks in advance,
Yakov
I`m a beginner to JAVA.
Have an exercise to write a program that converts money sum to number of bills and coins and prints it. f.e.:
47.63 =
4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickles
3 pennies
I wrote it in different ways but the MONEY value seems to lose precision after arithmetic operations on it.
whether I do it like that :
DOLLAR_100 = (int) MONEY / 100;
MONEY = MONEY % 100;
or even without changing the value of money:
DOLLAR_100 = (int) MONEY /100;
DOLLAR_50 = (int) MONEY %100 / 50;
It loses precision as seen in the images.
Please help,
Thanks in advance,
Yakov