Java tutorial
//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 MIN_POSITIVE_DECIMAL_NUMBER = new BigDecimal("0.000000000000001"); protected static final BigDecimal MAX_POSITIVE_DECIMAL_NUMBER = new BigDecimal(10e15) .subtract(MIN_POSITIVE_DECIMAL_NUMBER); protected static final BigDecimal MIN_NEGATIVE_DECIMAL_NUMBER = new BigDecimal(-10e14) .add(new BigDecimal("0.000000000000001")); protected static final BigDecimal MAX_NEGATIVE_DECIMAL_NUMBER = MIN_POSITIVE_DECIMAL_NUMBER.negate(); public static boolean displayedAsScientific(Object number) { BigDecimal num = getBigDecimal(number); if (num.compareTo(MAX_POSITIVE_DECIMAL_NUMBER) <= 0 && num.compareTo(MIN_POSITIVE_DECIMAL_NUMBER) >= 0) { return false; } if (num.compareTo(MAX_NEGATIVE_DECIMAL_NUMBER) <= 0 && num.compareTo(MIN_NEGATIVE_DECIMAL_NUMBER) >= 0) { return false; } return true; } private static BigDecimal getBigDecimal(Object number) { BigDecimal num = null; if (number instanceof BigDecimal) { num = (BigDecimal) number; } else { num = new BigDecimal(number.toString()); } return num; } }