如果你在JVM上,你可以使用
"%,d".format(input)
输入11000
等于11,000
.将,
替换为所需的任何分隔符.
If you want to use predefined number formats, e.g. for the current locale, use:
java.text.NumberFormat.getIntegerInstance().format(input);
Be also sure to check the other format instances, e.g. getCurrencyInstance
or getPercentInstance
. Note that you can use NumberFormat
also with other locales. Just pass them to the get*Instance
-method.
Some of the second variant can also be found here: Converting Integer to String with comma for thousands
If you are using it via Javascript you may be interested in: How do I format numbers using JavaScript?