add commas or point every 3 digits using kotlin
System.out.println(NumberFormat.getNumberInstance(Locale.US).format(35634646));
If you are on the JVM you can use
"%,d".format(input)
which gives 11,000
for input 11000
. Replace ,
with any delimiter you require.
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?