python保留两位小数: In [1]: a = 5.026 In [2]: b = 5.000 In [3]: round(a,2) Out[3]: 5.03 In [4]: round(b,2) Out[4]: 5.0 In [5]: '%.2f' % a Out[5]: '5.03' In [6]: '%.2f' % b Out[6]: '5.00' In [7]: float('%.2f' % a) Out[7]: 5.03 In [8]: float('%.2f' % b) Out[
转载自 http://blog.csdn.net/com_stu_zhang/article/details/7214565 方法1: float f = 34.232323; BigDecimal b = new BigDecimal(f); float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); // b.setScale(2, BigDecimal.ROUND
方法1: float f = 34.232323; BigDecimal b = new BigDecimal(f); float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); // b.setScale(2, BigDecimal.ROUND_HALF_UP) 表明四舍五入,保留两位小数 float ft = 134.3435f; int scale = 2
public class $66 { public static void main(String agrs[]) { float a=(float) 1.123456789;//8位 System.out.println(a);//1.1234568 double aa=10.123456789123456789;//17位 System.out.println(aa);// 10.123456789123457 } } public class $66 { public static voi
python保留两位小数: In [1]: a = 5.026 In [2]: b = 5.000 In [3]: round(a,2) Out[3]: 5.03 In [4]: round(b,2) Out[4]: 5.0 In [5]: '%.2f' % a Out[5]: '5.03' In [6]: '%.2f' % b Out[6]: '5.00' In [7]: float('%.2f' % a) Out[7]: 5.03 In [8]: float('%.2f' % b) Out[
#数字转字符保留几位小数 by gisoracle #数字转字符保留几位小数 by gisoracle def floattostr(num,xsnum): if xsnum==0: return str(int(num)) nd=round(num,xsnum) nstr=str(nd) idx=nstr.index('.') print idx p=len(nstr)-idx-1 print p n=xsnum-p print n s="" for i in range(n): s