📌  相关文章
📜  Java中的 NumberFormat isParseIntegerOnly() 方法及示例

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

Java中的 NumberFormat isParseIntegerOnly() 方法及示例

isParseIntegerOnly()方法是Java.text.NumberFormat 的内置方法,如果将数字解析为这种格式的整数,则返回 true。例如,在英语语言环境中,ParseIntegerOnly 为 true,字符串“5678”。将被解析为整数值 5678,并且解析将在“.”处停止。字符。

句法:

public boolean isParseIntegerOnly()

参数:该函数不接受任何参数。

返回值:该函数返回一个布尔值,如果数字可以解析为整数,则返回true,否则返回false。

下面是上述函数的实现:

程序 1

Java
// Java program to implement
// the above function
 
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
 
public class Main {
    public static void main(String[] args)
        throws Exception
    {
 
        // Get the instance for Locale US
        NumberFormat nF
            = NumberFormat
                  .getPercentInstance(
                      Locale.US);
 
        // Check
        if (nF.isParseIntegerOnly())
            System.out.println("isParseIntegerOnly: Yes");
        else
            System.out.println("isParseIntegerOnly: No");
    }
}


Java
// Java program to implement
// the above function
 
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
 
public class Main {
    public static void main(String[] args)
        throws Exception
    {
 
        // Get the instance for Locale CANADA
        NumberFormat nF
            = NumberFormat
                  .getPercentInstance(
                      Locale.CANADA);
 
        // Check
        if (nF.isParseIntegerOnly())
            System.out.println("isParseIntegerOnly: Yes");
        else
            System.out.println("isParseIntegerOnly: No");
    }
}


输出:
isParseIntegerOnly: No

方案二:

Java

// Java program to implement
// the above function
 
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
 
public class Main {
    public static void main(String[] args)
        throws Exception
    {
 
        // Get the instance for Locale CANADA
        NumberFormat nF
            = NumberFormat
                  .getPercentInstance(
                      Locale.CANADA);
 
        // Check
        if (nF.isParseIntegerOnly())
            System.out.println("isParseIntegerOnly: Yes");
        else
            System.out.println("isParseIntegerOnly: No");
    }
}
输出:
isParseIntegerOnly: No

参考:https: Java/text/NumberFormat.html#isParseIntegerOnly()