Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

import java.math.BigDecimal;

public class Main {
    protected static final BigDecimal MAX_DOUBLE = new BigDecimal(Double.MAX_VALUE);
    protected static final BigDecimal MIN_DOUBLE = MAX_DOUBLE.negate().subtract(BigDecimal.ONE);

    public static boolean isBigNumber(Object number) {
        if (number == null) {
            return false;
        }
        try {
            BigDecimal num = getBigDecimal(number);
            if (num.compareTo(MAX_DOUBLE) == 1 || num.compareTo(MIN_DOUBLE) == -1) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
    }

    private static BigDecimal getBigDecimal(Object number) {
        BigDecimal num = null;
        if (number instanceof BigDecimal) {
            num = (BigDecimal) number;
        } else {
            num = new BigDecimal(number.toString());
        }
        return num;
    }
}