Skip to content
Related Articles

Related Articles

java.time.format.DecimalStyle Class in Java
  • Last Updated : 03 Mar, 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

decimalSeperator() Method:

Java




// Java program to demonstrate the
// Implementation of decimalSeperator()
    
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 seperation: "
            + x.getDecimalSeparator()); 
    
        char decimalSeparator = '*'
    
        DecimalStyle ds = x.withDecimalSeparator( decimalSeparator); 
    
        System.out.println( "Char after seperation: "
            + ds.getDecimalSeparator()); 
    
Output
Char before seperation: .
Char after seperation: *

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

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :