package com.testEmp; import java.text.DecimalFormat; public class NumberFormat { public static void main(String[] args) { System.out.println(toWestNumFormat(1)); System.out.println(toWestNumFormat(123)); System.out.println(toWestNumFormat(145676)); System.out.println(toWestNumFormat(1324323213)); System.out.println(toWestNumFormat(1321333334567432432L)); } /** * 将整数在千分位以逗号分隔 * @param number * @return */ public static String toWestNumFormat(long number) { DecimalFormat df = new DecimalFormat("#,###"); return df.format(number); } }
输出:
1 123 145,676 1,324,323,213 1,321,333,334,567,432,432
--END-- 2019年10月4日21:30:54