CORE API / CATATAN</>↗Core API20 Agt 2010
The DateFormat class allows you to format dates and times with predefined styles in a locale-sensitive manner. Formatting dates or times with the DateFormat class is a two-step process. First, you create a formatter with the getDateInstance() method for formatting date or getTimeInstance() method for formatting time or getDateTimeInstance() when you want formatting both date […]
CORE API / CATATAN</>↗Core API15 Agt 2010
This example show you how to change the currency symbol for the defined locale using the DecimalFormatSymbols.setCurrencySymbol() method. After changing the currency symbol, the DecimalFormatSymbols instance is passed to the DecimalFormat object which does the formatting. package org.kodejava.text; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.Locale; public class CurrencyFormatSymbols { public static vo...
CORE API / CATATAN</>↗Core API12 Agt 2010
You can use the DecimalFormatSymbols class to change the symbols that appear in the formatted numbers. These symbols include the decimal separator which can be changed using the setDecimalSeparator(), the grouping separator which can be change using the setGroupingSeparator() method. You can also alter the minus sign, and the percent sign, among others. package org.kodejava.text; […]
CORE API / CATATAN</>↗Core API11 Agt 2010
To change the pattern use by the DecimalFormat when formatting a number we can use the DecimalFormat.applyPattern() method call. In this example we use three different patterns to format the given input number. The pattern determines what the formatted number looks like. package org.kodejava.text; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Locale; public class FormatterPattern { public […]
CORE API / CATATAN</>↗Core API08 Agt 2010
The NumberFormat.getPercentInstance() method returns a percentage format for the specified locale. In this example we will format the number as percentage using the Locale.US locale. package org.kodejava.text; import java.text.NumberFormat; import java.util.Locale; public class LocalePercentageFormat { public static void main(String[] args) { // Format percentage for Locale.US locale with this formatter, // a decimal fraction such […]
CORE API / CATATAN</>↗Core API04 Agt 2010
Creating a financial application requires you to format number as a currency. It should include the correct thousand separator, decimal separator and the currency symbol. For this purpose you can use the NumberFormat.getCurrencyInstance() method and pass the correct Locale to get the currency format that you want. package org.kodejava.text; import java.text.NumberFormat; import java.util.Locale; public class […]