Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

java.time.format.DecimalStyle Class in Java

  • Last Updated : 28 Jun, 2021

java.time.format.DecimalStyle class acts as a central point for accessing the information. A significant part of handling dates and times is that localization. This class provides localized decimal style utilized in date and time formatting. Clone, finalize, getClass, notify, notifyAll, wait, are the methods that are declared in this class.

Syntax:

public final class DecimalStyle extends Object

decimalSeparator() Method:

Java




// Java program to demonstrate the
// Implementation of decimalSeparator()
   
import java.time.format.*;
import java.util.*;
   
public class Example1 {
    public static void main(String[] args)
    {
   
        DecimalStyle x = DecimalStyle.STANDARD;
   
        System.out.println( "Char before separation: "
            + x.getDecimalSeparator());
   
        char decimalSeparator = '*';
   
        DecimalStyle ds = x.withDecimalSeparator( decimalSeparator);
   
        System.out.println( "Char after separation: "
            + ds.getDecimalSeparator());
    }
}
Output
Char before separation: .
Char after separation: *

getNegativeSign() Method:

Java




// Java program to demonstrate the
// Implementation of getNegativeSign()
   
import java.time.format.*;
import java.util.*;
   
public class Example2 {
    public static void main(String[] args)
    {
   
        DecimalStyle x = DecimalStyle.STANDARD;
   
        System.out.println("Character used "
                           + "for negative sign: "
                           + x.getNegativeSign());
    }
}
Output
Character used for negative sign: -

Methods Table:

METHODDESCRIPTION
equals​(Object obj)Checks if this DecimalStyle is equal to another DecimalStyle.
getAvailableLocales()Lists all the locales that are supported.
getDecimalSeparator()Gets the character that represents the decimal point.
getNegativeSign()Gets the character that represents the negative sign.
getPositiveSign()Gets the character that represents the positive sign.
getZeroDigit()Gets the character that represents zero.
hashCode()This provides the hashcode for this DecimalStyle. 
of(Locale locale)Provides the DecimalStyle for the Specified locale.
ofDefaultLocale()Provided the DecimalStyle for the default FORMAT locale.
toString()This will returns a string describing this DecimalStyle.
withDecimalSeparator​(char decimalSeparator)Returns a copy of the info with a new character that represents the decimal point.
withNegativeSign​(char negativeSign)Returns a copy with a new character that represents the negative sign.
withPositiveSign​(char positiveSign)Returns a copy with a new character that represents the positive sign.
withZeroDigit​(char zeroDigit)Returns a copy with a new character that represents zero.

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/format/DecimalStyle.html


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!