@Test public void getWanUnitString() { System.out.println("-----getWanUnitString test-----"); System.out.println(NumberUtil.getWanUnitString(1000, "w")); System.out.println(NumberUtil.getWanUnitString(1234567, "w")); System.out.println(NumberUtil.getWanUnitString(-1234567, "w")); System.out.println(NumberUtil.getWanUnitString(1234567.8, "万")); System.out.println(NumberUtil.getWanUnitString(1234567, null)); }
public static String getWanUnitString(double num , String unit) { String uc; if (unit == null || unit.isEmpty()) { unit = "w"; } if (Math.abs(num) < 10000) { uc = String.valueOf(num); } else { float value = (float) (num / 10000.0); if (value >= 100.0 || num % 10000 == 0) { uc = Math.round((float) (num / 10000.0)) + unit; } else { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(1, BigDecimal.ROUND_DOWN); uc = bd + ""; if (uc.endsWith(".0")) { uc = Math.round(value) + unit; } else { uc = uc + unit; } } } return uc; }
NumberUtil { public static String getWanUnitString(double num , String unit) { String uc; if (unit == null || unit.isEmpty()) { unit = "w"; } if (Math.abs(num) < 10000) { uc = String.valueOf(num); } else { float value = (float) (num / 10000.0); if (value >= 100.0 || num % 10000 == 0) { uc = Math.round((float) (num / 10000.0)) + unit; } else { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(1, BigDecimal.ROUND_DOWN); uc = bd + ""; if (uc.endsWith(".0")) { uc = Math.round(value) + unit; } else { uc = uc + unit; } } } return uc; } }
NumberUtil { public static String getWanUnitString(double num , String unit) { String uc; if (unit == null || unit.isEmpty()) { unit = "w"; } if (Math.abs(num) < 10000) { uc = String.valueOf(num); } else { float value = (float) (num / 10000.0); if (value >= 100.0 || num % 10000 == 0) { uc = Math.round((float) (num / 10000.0)) + unit; } else { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(1, BigDecimal.ROUND_DOWN); uc = bd + ""; if (uc.endsWith(".0")) { uc = Math.round(value) + unit; } else { uc = uc + unit; } } } return uc; }  }
NumberUtil { public static String getWanUnitString(double num , String unit) { String uc; if (unit == null || unit.isEmpty()) { unit = "w"; } if (Math.abs(num) < 10000) { uc = String.valueOf(num); } else { float value = (float) (num / 10000.0); if (value >= 100.0 || num % 10000 == 0) { uc = Math.round((float) (num / 10000.0)) + unit; } else { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(1, BigDecimal.ROUND_DOWN); uc = bd + ""; if (uc.endsWith(".0")) { uc = Math.round(value) + unit; } else { uc = uc + unit; } } } return uc; }  static int optInt(String numStr, int def); static long optLong(String numStr, long def); static float optFloat(String numStr, float def); static double optDouble(String numStr, double def); static String getWanUnitString(double num , String unit); static String getThousandSeparatorFormat(double num); }
NumberUtil { public static String getWanUnitString(double num , String unit) { String uc; if (unit == null || unit.isEmpty()) { unit = "w"; } if (Math.abs(num) < 10000) { uc = String.valueOf(num); } else { float value = (float) (num / 10000.0); if (value >= 100.0 || num % 10000 == 0) { uc = Math.round((float) (num / 10000.0)) + unit; } else { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(1, BigDecimal.ROUND_DOWN); uc = bd + ""; if (uc.endsWith(".0")) { uc = Math.round(value) + unit; } else { uc = uc + unit; } } } return uc; }  static int optInt(String numStr, int def); static long optLong(String numStr, long def); static float optFloat(String numStr, float def); static double optDouble(String numStr, double def); static String getWanUnitString(double num , String unit); static String getThousandSeparatorFormat(double num);  }