NumberFormat isParseIntegerOnly() method in Java with Examples
Last Updated :
01 Dec, 2020
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
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
public class Main {
public static void main(String[] args)
throws Exception
{
NumberFormat nF
= NumberFormat
.getPercentInstance(
Locale.US);
if (nF.isParseIntegerOnly())
System.out.println( "isParseIntegerOnly: Yes" );
else
System.out.println( "isParseIntegerOnly: No" );
}
}
|
Output:
isParseIntegerOnly: No
Program 2:
Java
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;
public class Main {
public static void main(String[] args)
throws Exception
{
NumberFormat nF
= NumberFormat
.getPercentInstance(
Locale.CANADA);
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()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...