![]() To format a decimal with specific decimal precision we can set a RoundingMode. The previous code will generate the following output: Formatted euro currency: €1,234.46įormatted dollar currency: $1,234.46 Decimal Rounding ("Formatted dollar currency: " + n.format(amount)) NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US) ("Formatted euro currency: " + euroFormat.format(amount)) double amount = 1234.4567 ĭecimalFormat euroFormat = new DecimalFormat("€#,#0.00") To display a currency symbol we can either provide a currency symbol in the pattern, or obtain a localized instance of the NumberFormat. The previous code will generate the following output: Formatted decimal pattern: 1,2345,6789.46įormatted decimal grouping size 5: 1234,56789.46įormatted decimal no grouping: 123456789.46 Displaying and Configuring Currency Symbol ("Formatted decimal no grouping: " + df.format(amount)) ![]() ("Formatted decimal grouping size 5: " + df.format(amount)) ("Formatted decimal pattern: " + df.format(amount))
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |