Friday, September 5, 2025
HomeLanguagesJavaNumberFormat isParseIntegerOnly() method in Java with Examples

NumberFormat isParseIntegerOnly() method in Java with Examples

The isParseIntegerOnly() method is a built-in method of the java.text.NumberFormat which returns true if numbers are parsed as integers in this format. For example in the English locale, with ParseIntegerOnly true, the string “5678.” would be parsed as the integer value 5678 and parsing would stop at the “.” character. 

Syntax:  

public boolean isParseIntegerOnly()

Parameters: The function does not accept any parameter.

Return Value: The function returns a boolean value, it returns true if numbers can be parsed as integers, else it returns false. 

Below is the implementation of the above function:

Program 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");
    }
}


Output: 

isParseIntegerOnly: No

 

Program 2: 

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


Output: 

isParseIntegerOnly: No

 

Reference: https://docs.oracle.com/javase/10/docs/api/java/text/NumberFormat.html#isParseIntegerOnly()
 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS