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()
Please Login to comment...