Float保留两位小数或多位小数

方法1:orm

//
float i = 34.33333;
//四舍五入,只显示小数点后两位
BigDecimal b   =   new   BigDecimal(i);
float   f1   =   b.setScale(2,   BigDecimal.ROUND_HALF_UP).floatValue();
mToLearnTimes.setText("已选课程:"+ f1+"小时");
//   b.setScale(2,   BigDecimal.ROUND_HALF_UP)   代表四舍五入,保留两位小数

方法2:  ci

float   scale   =   34.236323;
DecimalFormat   fnum   =   new   DecimalFormat("##0.00");
String   dd=fnum.format(scale);

方法3:form

float   a   =   123.2334f;
float   b   =   (float)(Math.round(a*100))/100;(这里的100就是2位小数点,若是要其它位,如4位,这里两个100改为10000)
相关文章
相关标签/搜索