Ad
Ad
Ad
Category

Java

Category

Class DecimalFormatSymbols in Java

DecimalFormatSymbols class defines the various characters and strings, such as the decimal point, percent sign, and thousands separator, used by DecimalFormat when formatting numbers. We do not typically use this class directly unless we are formatting dates for an unsupported locale or in some highly customized way.

The DecimalFormatSymbols class encapsulates number-formatting data that is locale-specific, like grouping separators and decimal separators. Typically, we do not need to instantiate DecimalFormatSymbols ourselves. Instead, an instance is automatically created for us, behind the scenes, when we use one of the factory methods in NumberFormat to create a DecimalFormat object.

We can retrieve a DecimalFormatSymbols object by calling the getDecimalFormatSymbols()
method of DecimalFormat. Once we have a DecimalFormatSymbols object, we can modify the strings it uses if you want to change them.

The class structure for the class DecimalFormatSymbols is given as

public final class java.text.DecimalFormatSymbols extends java.lang.Object implements java.lang.Cloneable,java.io.Serializable {
// Public Constructors
public DecimalFormatSymbols();
public DecimalFormatSymbols(Locale locale);
// Public Instance Methods
public Object clone(); // Overrides Object
public boolean equals(Object obj); // Overrides Object
public char getDecimalSeparator();
public char getDigit();
public char getGroupingSeparator();
public String getInfinity();
public char getMinusSign();
public String getNaN();
public char getPatternSeparator();
public char getPerMill();
public char getPercent();
public char getZeroDigit();
public int hashCode(); // Overrides Object
public void setDecimalSeparator(char decimalSeparator);
public void setDigit(char digit);
public void setGroupingSeparator(char groupingSeparator);
public void setInfinity(String infinity);
public void setMinusSign(char minusSign);
public void setNaN(String NaN);
public void setPatternSeparator(char patternSeparator);
public void setPerMill(char perMill);
public void setPercent(char percent);
public void setZeroDigit(char zeroDigit);
}

The details of the class structure are given as follows:

public DecimalFormatSymbols();

public DecimalFormatSymbols() constructor creates a DecimalFormatSymbols object for the default locale.

public DecimalFormatSymbols(Locale locale);

public DecimalFormatSymbols(Locale locale) constructor creates a DecimalFormatSymbols object for the given locale.

Parameter
locale – The Locale to use.

public Object clone();

public Object clone() method creates a copy of this DecimalFormatSymbols and returns it.

This method returns a copy of this DecimalFormatSymbols.

public boolean equals(Object obj);

public boolean equals(Object obj) method returns true if obj is an instance of DateFormatSymbols and is equivalent to this DecimalFormatSymbols.

This method returns true if the objects are equal; false if they are not.

Parameter
obj – The object to be compared with this object.

public char getDecimalSeparator();

public char getDecimalSeparator() method returns the decimal separator character (e.g., “.”, “,”).

This method returns the character used to separate the integer and fractional parts of a number for this DecimalFormatSymbols.

public char getDigit();

public char getDigit() method returns the digit pattern character, which represents a digit that is not shown if it is zero.
This method returns the character used to represent a digit in a pattern string for this DecimalFormatSymbols.

public char getGroupingSeparator();

public char getGroupingSeparator() method returns the grouping separator character (e.g., “,”, “.”).

This method returns the character used to separate long numbers for this DecimalFormatSymbols.

public String getInfinity();

public String getInfinity() method returns the string that represents infinity.

This method returns the string used to represent infinity for this DecimalFormatSymbols.

public char getMinusSign();

public char getMinusSign() method returns the character that signifies negative numbers.

This method returns the character used to signify negative numbers for this DecimalFormatSymbols.

public String getNaN();

public String getNaN() method returns the string that represents not-a-number.

This method returns the string used to represent the value not-a-number for this DecimalFormatSymbols.

public char getPatternSeparator();

public char getPatternSeparator() method returns the character used in pattern strings to separate the positive subpattern and negative subpattern.

This method returns the pattern separator character for this DecimalFormatSymbols.

public char getPerMill();

public char getPerMill() method returns the character that represents a per mille value.

This method returns the character used to represent the per mille sign for this DecimalFormatSymbols.

public char getPercent();

public char getPercent() method returns the character that represents a percent value (e.g., %).

This method returns the character used to represent the percent sign for this DecimalFormatSymbols.

public char getZeroDigit();

public char getZeroDigit() method returns the zero-digit pattern character, which represents a digit that is shown even if it is zero.

This method returns the character used to represent a digit in a pattern string for this DecimalFormatSymbols.

public int hashCode();

public int hashCode() method returns a hashcode for this DecimalFormatSymbols object.

This method returns a hashcode for this object.

public void setDecimalSeparator(char decimalSeparator);

public void setDecimalSeparator(char decimalSeparator) method sets the decimal separator character for this DecimalFormatSymbols.

Parameter
decimalSeparator – The new decimal separator.

public void setDigit(char digit);

public void setDigit(char digit) method sets the digit pattern character, which represents a digit that is not shown if it is zero, for this DecimalFormatSymbols.

Parameter
digit – The new digit pattern character.

public void setGroupingSeparator(char groupingSeparator);

public void setGroupingSeparator(char groupingSeparator) method sets the grouping separator character for this DecimalFormatSymbols.

Parameter
groupingSeparator – The new grouping separator.

public void setInfinity(String infinity);

public void setInfinity(String infinity) method sets the string that represents infinity for this DecimalFormatSymbols.

Parameter
infinity – The new infinity string.

public void setMinusSign(char minusSign);

public void setMinusSign(char minusSign) method sets the character that signifies negative numbers for this DecimalFormatSymbols.

Parameter
minusSign – The new minus sign.

public void setNaN(String NaN);

public void setNaN(String NaN) method sets the string that represents not-a-number for this DecimalFormatSymbols.

Parameter
NaN – The new non-a-number string.

public void setPatternSeparator(char patternSeparator);

public void setPatternSeparator(char patternSeparator) method sets the character that is used in pattern strings to separate the positive subpattern and negative subpattern for this DecimalFormatSymbols.

Parameter
patternSeparator – The new pattern separator.

public void setPerMill(char perMill);

public void setPerMill(char perMill) method sets the character that represents the per mille sign for this DecimalFormatSymbols.

Parameter
perMill – The new per mille sign.

public void setPercent(char percent);

public void setPercent(char percent) method sets the character that represents the percent sign for this DecimalFormatSymbols.

Parameter
percent – The new percent sign.

public void setZeroDigit(char zeroDigit);

public void setZeroDigit(char zeroDigit) method sets the zero-digit pattern character, which represents a digit that is shown even if it is zero, for this DecimalFormatSymbols.

Parameter
zeroDigit – The new zero-digit pattern character.

Apart from these methods DecimalFormatSymbols class also has inherited methods from class- Object. They are as follows:

  • finalize()
  • notifyAll()
  • wait()
  • wait(long, int)
  • getClass()
  • notify()
  • toString()
  • wait(long)