java.text.DecimalFormat
DecimalFormat 在 java.text 包里
对数字进行转换的类
publicstaticvoidmain(String[]args){StringfeeStr="2145";//以分为单位DecimalFormatdf1=newDecimalFormat("##.##");Stringfee1=df1.format((Double.parseDouble(feeStr)/100));DecimalFormatdf2=newDecimalFormat("0.00");Stringfee2=df2.format((Double.parseDouble(feeStr)/100));DecimalFormatdf3=newDecimalFormat(".##");Stringfee3=df3.format((Double.parseDouble(feeStr)/100));System.out.println("fee1="+fee1+",fee2="+fee2+",fee3="+fee3);}
结果:
fee1=21.45fee2=21.45fee3=21.45
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。