Java十进制格式错误输出

问题描述 投票:0回答:1

我正在尝试打印出特定的双精度十进制格式,但它没有以我希望的打印方式打印出来。例如,代替打印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(); 
}
java double decimalformat
1个回答
1
投票

如果您想使用美国格式,则必须这样说:

DecimalFormat decimal = new DecimalFormat("#.00", DecimalFormatSymbols.getInstance(Locale.US));
© www.soinside.com 2019 - 2024. All rights reserved.