Java BigDecimal tryToStoreAsRealBigDecimal(Object ob)

Here you can find the source of tryToStoreAsRealBigDecimal(Object ob)

Description

try To Store As Real Big Decimal

License

Apache License

Declaration

private static BigDecimal tryToStoreAsRealBigDecimal(Object ob) 

Method Source Code

//package com.java2s;
/**/*from  ww  w  .j  a  va2 s .com*/
 * *****************************************************************************
 * Copyright 2007 Amazon Technologies, Inc. Licensed under the Apache License, Version 2.0 (the "License");
 *
 * You may not use this file except in compliance with the License. You may obtain a copy of the License at: http://aws.amazon.com/apache2.0 This file is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 * ***************************************************************************** __ _ _ ___ ( )( \/\/ )/ __) /__\ \ / \__ \ (_)(_) \/\/ (___/
 *
 * Amazon Simple DB Java Library API Version: 2007-11-07 Generated: Fri Jan 18 01:13:17 PST 2008
 *
 */

import java.math.BigDecimal;

public class Main {
    private static BigDecimal tryToStoreAsRealBigDecimal(Object ob) {
        BigDecimal bigDecimal = null;
        if (canBeStoredAsRealBigDecimal(ob)) {
            bigDecimal = new BigDecimal(ob.toString());
        } else if (ob instanceof BigDecimal) {
            bigDecimal = (BigDecimal) ob;
        }

        return bigDecimal;
    }

    private static boolean canBeStoredAsRealBigDecimal(Object ob) {
        if (isNaN(ob) || isInfinite(ob)) {
            return false;
        }

        return ob instanceof Double || ob instanceof Float;
    }

    public static boolean isNaN(Object ob) {
        return (ob instanceof Double && ((Double) ob).isNaN()) || (ob instanceof Float && ((Float) ob).isNaN());
    }

    public static boolean isInfinite(Object ob) {
        return (ob instanceof Double && ((Double) ob).isInfinite())
                || (ob instanceof Float && ((Float) ob).isInfinite());
    }
}

Related

  1. tanto(BigDecimal r, BigDecimal n)
  2. textToBigDecimal(String amountAsText)
  3. transferDonateAmount2Point(BigDecimal donateAmount)
  4. tryParseBigDecimal(Object val, BigDecimal defaultVal)
  5. tryToStoreAsIntegerBigDecimal(Object ob)
  6. unformattedFromBigDecimal(BigDecimal n)
  7. unformattedToBigDecimal(String str)
  8. valueOf(final BigDecimal value)
  9. writeBigDecimal(BigDecimal val, DataOutput out)