Sunday, October 12, 2025
HomeLanguagesJavaDecimalFormat applyLocalizedPattern() method in Java

DecimalFormat applyLocalizedPattern() method in Java

The applyLocalizedPattern() Method of DecimalFormat class in Java is used to apply a localized string pattern to this Decimal format. This pattern can be set by the user.

Syntax:

public void applyLocalizedPattern(String pattern)

Parameters: The method takes one parameter pattern of String type and refers to the pattern which will be used to format the DecimalPattern.

Return Value: The method returns void type.

Below programs illustrate the working of applyLocalizedPattern() Method:

Program 1:




// Java program to illustrate the
// applyLocalizedPattern method
  
import java.text.DecimalFormat;
  
public class Main {
    public static void main(String[] args)
    {
  
        DecimalFormat deciFormat = new DecimalFormat();
  
        deciFormat.applyLocalizedPattern("##, ##");
        System.out.println(deciFormat.format(-123456789.54321));
    }
}


Output:

-1, 23, 45, 67, 90

Program 2:




// Java program to illustrate the
// applyLocalizedPattern method
  
import java.text.DecimalFormat;
  
public class Main {
    public static void main(String[] args)
    {
  
        DecimalFormat deciFormat = new DecimalFormat();
  
        deciFormat.applyLocalizedPattern("#, #00.0#");
        System.out.println(deciFormat.format(-123456789.54321));
    }
}


Output:

-123, 456, 789.54

Reference: https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html#applyLocalizedPattern(java.lang.String)

RELATED ARTICLES

Most Popular

Dominic
32352 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6720 POSTS0 COMMENTS
Nicole Veronica
11885 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6840 POSTS0 COMMENTS
Ted Musemwa
7105 POSTS0 COMMENTS
Thapelo Manthata
6795 POSTS0 COMMENTS
Umr Jansen
6795 POSTS0 COMMENTS