📜  Java的.time.format.DecimalStyle类在Java中

📅  最后修改于: 2022-05-13 01:54:54.593000             🧑  作者: Mango

Java的.time.format.DecimalStyle类在Java中

Java.time.format.DecimalStyle类充当访问信息的中心点。处理日期和时间的一个重要部分是本地化。此类提供在日期和时间格式中使用的本地化十进制样式。 Clone、finalize、getClass、notify、notifyAll、wait,都是在这个类中声明的方法。

句法:

public final class DecimalStyle extends Object

decimalSeparator() 方法:

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());
    }
}


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());
    }
}


输出
Char before separation: .
Char after separation: *

getNegativeSign() 方法:



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());
    }
}
输出
Character used for negative sign: -

方法表:

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.

参考:https://docs.oracle.com/javase/8/docs/api/的Java/time/format/DecimalStyle.html