2017-06-01 39 views
0

我有這種方法;聲納死亡存儲到局部變量NumberFormat java

private static String formatVolumeForLife(String rateBasisValue, String volumeValue) { 
    NumberFormat formatter = new DecimalFormat(); 
    if(PER_UNIT.equals(rateBasisValue) || PER_DEPENDENT_PER_UNIT_PER_MONTH.equals(rateBasisValue)){ 
     formatter = new DecimalFormat(FORMAT_NUMBER_WITH_COMMA); 
    } else { 
     formatter = new DecimalFormat(FORMAT_CURRENCY); 
    } 
    String formattedVolume = formatter.format(Double.parseDouble(volumeValue)); 
    return formattedVolume; 
} 

聲納抱怨「聲納死亡商店本地變量格式化」。

是否需要更改NumberFormat formatter = new DecimalFormat();?

回答

3

創建的對象從不使用。將代碼更改爲

private static String formatVolumeForLife(String rateBasisValue, String volumeValue) { 
    NumberFormat formatter; 
    if(PER_UNIT.equals(rateBasisValue) || PER_DEPENDENT_PER_UNIT_PER_MONTH.equals(rateBasisValue)){ 
     formatter = new DecimalFormat(FORMAT_NUMBER_WITH_COMMA); 
    } else { 
     formatter = new DecimalFormat(FORMAT_CURRENCY); 
    } 
    return formatter.format(Double.parseDouble(volumeValue)); 
} 
+0

謝謝Matthias – Darren