Answers for "how to include comma separator for thousands java"

1

java add commas to numbers

String number = "1000500000.574";
double amount = Double.parseDouble(number);
DecimalFormat formatter = new DecimalFormat("#,###.00");
// the zeroes after the point are the number of digits shown after the period
// you can also switch point and commas and get for example 1.002,45
System.out.println(formatter.format(amount));
// this prints 1,000,500,000.57
Posted by: Guest on July-28-2021
0

print a number with commas as thousands separator

Example: 10000000.2345 -> '1,000,000.2345'
function numberWithCommas(x) {
    var parts = x.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
}
Posted by: Guest on October-19-2021

Code answers related to "how to include comma separator for thousands java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language