Java - Write code to check if a string is Number using BigDecimal constructor

Requirements

Write code to check if a string is Number using BigDecimal constructor

Demo

//package com.book2s;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] argv) {
        String value = "book2s.com";
        System.out.println(checkNumber(value));
    }//from w  ww  . j a  v  a2  s  . co m

    public static boolean checkNumber(String value) {
        try {
            new BigDecimal(value);
        } catch (Exception e) {
            // TODO: handle exception
            return false;
        }

        return true;
    }
}