Java去除数字里多余的0。

	public static String getPrettyNumber(String number) {
		return BigDecimal.valueOf(Double.parseDouble(number))
				.stripTrailingZeros().toPlainString();
	}

	public static void main(String[] args) {
		String intNumber = "00012340";
		System.out.println(getPrettyNumber(intNumber));
		String doubleNumber = "00012.340";
		System.out.println(getPrettyNumber(doubleNumber));
		
		String eNumber = "1.2e3";
		System.out.println(getPrettyNumber(eNumber));
	}


输出

12340
12.34
1200

你可能感兴趣的:(java,数字去掉0)