【发布时间】:2020-10-25 05:22:25
【问题描述】:
我被分配了一个问题来设计一个java程序来计算披萨的价格,这是我尝试的:
String diameter;
diameter = this.txtInput.getText();
// variable declaration and intialize for "labourCost" and "storeCost"
double labourCost, storeCost;
labourCost = 1;
storeCost = 1.5;
// convert the value inputted from a string to double
double dblDiameter= Double.parseDouble(diameter);
// variable declarationa and intialize the value for the variable "cost"
double cost = (labourCost + storeCost + (0.5 * dblDiameter));
// print the output
this.lblOutput.setText("The cost of the pizza is $" + cost);
我得到的输出是 7.5 美元,我的问题是如何格式化它以显示 7.50 美元?谢谢。
【问题讨论】:
标签: java decimal currency decimalformat