
Hi all. I'm writing a program where users input the cost of an item (in the constructor), so for example,
Item (string name, double cost, int qty) { ... }
I have a method
public double getCost() {
...
}
And I want it to return the cost. I tried using DecimalFormat, but I was told that it doesn't change the number itself. I need to return a Double, not a String!!
So when my client queries:
item.getCost()
They are give a double in return, example,
3.00
I tried this, but it didn't work:
DecimalFormat df = new DecimalFormat("#0.00");
String itemCost = (df.format(cost));
cost = Double.parseDouble(itemCost);
return cost;
}
It needs to return a string but I need it to return a double. Help please.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.