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));
    }/*www  .j  ava 2s .c o m*/

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

        return true;
    }
}

Related Exercise