Here you can find the source of isNumberInRange(String text, BigInteger min, BigInteger max)
Parameter | Description |
---|---|
text | a parameter |
min | a parameter |
max | a parameter |
public static boolean isNumberInRange(String text, BigInteger min, BigInteger max)
//package com.java2s; //License from project: Apache License import java.math.BigInteger; public class Main { /**/*from w ww .j a va2 s . co m*/ * Check whether the number is in range [min, max] inclusive. * <p> Any/Both of the min/max could be null, which would be ignored. * <p> Note, it's your responsibility to ensure min <= max if neither of them is null. * @param text * @param min * @param max * @return */ public static boolean isNumberInRange(String text, BigInteger min, BigInteger max) { BigInteger value = null; try { value = new BigInteger(text); } catch (Exception e) { // could be NullPointerException and MalformatException. return false; } if (min != null) { if (value.compareTo(min) < 0) { // smaller then min. return false; } } if (max != null) { if (value.compareTo(max) > 0) { return false; } } return true; } }