Skip to content

Instantly share code, notes, and snippets.

@ashour
Last active March 12, 2020 16:57
Show Gist options
  • Save ashour/7153d54e7a5156e993fba1e9e6875a5c to your computer and use it in GitHub Desktop.
Save ashour/7153d54e7a5156e993fba1e9e6875a5c to your computer and use it in GitHub Desktop.
import java.util.Locale;
import java.text.NumberFormat;
public class FormatNumbers {
public static void main(String []args) {
double number = 123456.78;
NumberFormat usFormatter = NumberFormat.getInstance(new Locale("en", "US"));
System.out.println(usFormatter.format(number));
// => 123,456.78 (American format)
NumberFormat frenchFormatter = NumberFormat.getInstance(new Locale("fr", "FR"));
System.out.println(frenchFormatter.format(number));
// => 123 456,78 (French format)
NumberFormat thaiFormatter =
NumberFormat.getInstance(new Locale("th", "TH", "TH"));
System.out.println(thaiFormatter.format(number));
// => ๑๒๓,๔๕๖.๗๘ (Thai format)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment