How to get these formats in java?
Input:
1223893 180703 80967 1461 700
Output:
1,223,893 180,703 80,967 1,461 700
I will always convert one at a time, this is just to get more examples.
you can read java number formatting here
so that you do something like this:
DecimalFormat myFormatter = new DecimalFormat('###,###,###'); String output = myFormatter.format('1223893');
if you output var, it should have 1,223,893
output
1,223,893
Find the "grouping" and "thousands separator" here . DecimalFormatSymbols provides setGroupingSeparator(',') , and you can set it to DecimalFormat along with setGroupingSize(3) . To illustrate:
DecimalFormatSymbols
setGroupingSeparator(',')
DecimalFormat
setGroupingSize(3)
DecimalFormat df = new DecimalFormat(); df.getDecimalFormatSymbols().setGroupingSeparator(','); df.setGroupingSize(3); System.out.println(df.format(1223893)); // prints 1,223,893
You can use DecimalFormat .
google for NumberFormat in java
See api docs .
Take a look at the DecimalFormat class.
Source: https://habr.com/ru/post/1388067/More articles:R RODBC puts a list of numbers in an IN () statement - sqlJava: double format with decimals - javaTouch the AirPlay button area in MPVolumeView - iosIs sun.misc package still available in java? - javaLock a specific file during the "registration" process? - tfsPass R variable to RODBC sqlQuery with multiple records? - rThe titleLabel button is set to hidden YES, appears again when touched - iosThe float literal and range parameter in ANTLR - antlris it safe to pass the reference of the object of the exception object to the new exception object? - c ++How to create a regular expression that takes into account the number of occurrences, but not the appearance of a position? - regexAll Articles