重量WeightFormatUtil辅助类

mac2022-06-30  124

package com.jlb.scan.util; import java.text.DecimalFormat; public class WeightFormatUtil { public static String format(float number) { String str = number + ""; int pos = str.indexOf("."); if (pos < 0) return str; else { String pre = str.substring(0, pos); String last = str.substring(pos + 1); try { int xiaoshu = Integer.parseInt(last); if (xiaoshu == 0) { return pre; } else { StringBuilder sb = new StringBuilder(last); int i = last.length(); char[] chars = last.toCharArray(); while (i-- > 0) { String t = sb.substring(i,i+1); if (t.equals("0")) { sb.delete(i,i+1); } else { break; } } return pre + "." + sb.toString(); } } catch (NumberFormatException ex) { ex.printStackTrace(); } } DecimalFormat df = new DecimalFormat("##0.000"); return df.format(number); } }

 

转载于:https://www.cnblogs.com/xinmengwuheng/p/5886321.html

相关资源:微信小程序源码-合集4.rar
最新回复(0)