Search code examples
javaformatdecimal

convert number to String and separated with dot


I want convert number to String and separated with dot like 10000000 to 10.000.000 in java how it possible

this is work but I looking for better solution

int number  = 10000000;

NumberFormat format = NumberFormat.getNumberInstance(Locale.US);
            
System.out.println(format.format(number).replace(",","."));

Solution

  • Add this

    DecimalFormat decimalFormat = new DecimalFormat("#,###");
    return decimalFormat.format(number);