Last active
March 12, 2020 16:57
-
-
Save ashour/7153d54e7a5156e993fba1e9e6875a5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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