Originally Posted by
javaseek
There is one thing is left, I need to do. I was wondering if there any built-in method in java that can round the double number to two decimal places. I need it for the pies price. I want to change the price data type to double.
It is a sin to use double or float for currency.
Do not do it.
Never do it.
You can not get proper accounting accuracy, ever, with doubles for currency. So its better to get into the habit, today, of doing it properly.
The cleanest approach is to have a Money or Currency class, and incapsulate all the complexity.
What you must do is store the currency as a fixed point number.
So you store $9.93 per pizza as 993 pennies. Of if you are in the UK, store the number of pence.
Never use double for currency.