Java BigDecimal Parse parseTo_BigDecimal(String s)

Here you can find the source of parseTo_BigDecimal(String s)

Description

parse T Big Decimal

License

Open Source License

Declaration

public static BigDecimal parseTo_BigDecimal(String s) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.math.BigDecimal;

public class Main {
    public static BigDecimal parseTo_BigDecimal(String s) {
        if (isBlank(s)) {
            return null;
        }/*from w w w.j  a  v  a2 s . c om*/
        return new BigDecimal(s);
    }

    /**
     * Parse anything to BigDecimal
     *
     * @param input
     * @return
     */
    public static BigDecimal parseTo_BigDecimal(Number input) {
        if (input == null) {
            return null;
        }
        return new BigDecimal(input.toString());
    }

    public static BigDecimal parseTo_BigDecimal(byte input) {
        return new BigDecimal(input);
    }

    public static BigDecimal parseTo_BigDecimal(double input) {
        if (Double.isNaN(input)) {
            return null;
        }
        return BigDecimal.valueOf(input);
    }

    public static BigDecimal parseTo_BigDecimal(float input) {
        if (Float.isNaN(input)) {
            return null;
        }
        return BigDecimal.valueOf(input);
    }

    public static BigDecimal parseTo_BigDecimal(int input) {
        return new BigDecimal(input);
    }

    public static BigDecimal parseTo_BigDecimal(long input) {
        return new BigDecimal(input);
    }

    public static BigDecimal parseTo_BigDecimal(short input) {
        return new BigDecimal(input);
    }

    /**
     * StringUtils from apache commons-lang3 3.3.2
     *
     * We use this implementation in order to avoid using the common lang package and be compatible with any hadoop
     * distribution.
     *
     * Checks if a CharSequence is whitespace, empty ("") or null.
     *
     * @param cs the CharSequence to check, may be null
     * @returntrue if the CharSequence is null, empty or whitespace
     */
    public static boolean isBlank(final CharSequence cs) {
        int strLen;
        if (cs == null || (strLen = cs.length()) == 0) {

            return true;
        }

        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(cs.charAt(i)) == false) {
                return false;

            }
        }
        return true;
    }
}

Related

  1. parseBigDecimal(String data)
  2. parseBigDecimal(String inString, BigDecimal inDefault)
  3. parseBigDecimal(String number, BigDecimal defValue)
  4. parseBigDecimalForEntity(String bigDecimalString)
  5. parseTo_BigDecimal(String s)
  6. parseToBigDecimal(Object value)
  7. string2BigDecimal(String valor)
  8. stringToBigDecimal(String numeroStr)
  9. strToFloat(String text, int decimals)