Java Decimal格式输出错误



我正试图打印出一个特定的双精度小数格式,但它没有按我希望的方式打印出来。例如,它不是打印26.40,而是打印26,40。有人能帮帮我吗
提前感谢:(
这是我的代码:

DecimalFormat decimal= new DecimalFormat("#.00");
/* The following public method returns the estimated price of the CPU based on the supplied sQuarterYear variable*/
public double priceNow(String sQuarterYear){
double estimatedPrice = 0;
decimal.format(estimatedPrice);
int launch_year = Integer.parseInt(this.launch_date.substring(this.launch_date.length()-2)); // Initial launch Year
int launch_quarter = Integer.parseInt(this.launch_date.substring(1,this.launch_date.length()-3)); // Initial launch Quarter
int launch_year2 = Integer.parseInt(sQuarterYear.substring(sQuarterYear.length()-2)); // Supplied launch Year
int launch_quarter2 = Integer.parseInt(sQuarterYear.substring(1,sQuarterYear.length()-3)); // Supplied launch Quarter
int uncount_quarter = 4-launch_quarter2; // Quarter that are not counted
int count_year = 0;
for (int i = launch_year; i <= launch_year2; i++){
count_year++;
}       
int total_quarter = ((4*count_year) - launch_quarter - uncount_quarter);
/* Here, the supplied launch year and launch quarter will be compared and if the supplied QuarterYear is after the launch
* date (the supplied launch quarter and launch year are higher than the initial launch quarter and year, then it will calculate
* the depreciation */
if(launch_quarter2 >= launch_quarter && launch_year2>= launch_year){
estimatedPrice = suggprice - suggprice*total_quarter*0.02;
}
else
return estimatedPrice; /* If the supplied QuarterYear is before the launch date, there will be no depreciation and therefore will return the suggested price */
if (estimatedPrice < 0.0) // If the estimated price is lower than 0.0, then it will return the suggested price
return suggprice;
else
return estimatedPrice; /* Otherwise, it will calculate the estimated price and return it*/
}
/*The toString method to return all the values of a CPU object*/
public String toString(){
return "This CPU is " + this.generation + "th generation " + this.series.toString() + " (" + this.speed + "GHz), launched: " + this.launch_date.toString() + " with price: " + decimal.format(this.suggprice) + " USD. SGX is " + this.sgx_support.toString(); 
}

如果你想要美式格式,你必须这么说:

DecimalFormat decimal = new DecimalFormat("#.00", DecimalFormatSymbols.getInstance(Locale.US));

最新更新