Pretty simple question I imagine, just can't seem to figure out the right way to do it.
I have a method that produces my total "cost" (a pre-defined 'double' variable) as a dollar amount here:
import java.text.NumberFormat;
public class Example {
private double cost = 3.5;
NumberFormat cash = NumberFormat.getCurrencyInstance();
public String getTotal(){
String money = cash.format(cost);
return money;
}
}
This works & prints "$3.50" correctly.
I was wondering if it's possible to do something along the lines of:
public double getTotal(){
return cash.format(cost);
}
or
public double getTotal(){
double money = cash.format(cost);
return money;
}
Obviously the above doesn't compile, "cannot convert from String to double". Can I initiate the NumberFormat as a double instead of a String?
Seems completely unnecessary to me, this is the UML i'm trying to follow
+getTotal : double