Java BigDecimal Create getDecimalValue(String value, Object franctionDigits)

Here you can find the source of getDecimalValue(String value, Object franctionDigits)

Description

get Decimal Value

License

Open Source License

Declaration

public static Number getDecimalValue(String value, Object franctionDigits) 

Method Source Code


//package com.java2s;
/*//from   w ww. jav  a2  s.c  o m
 * Copyright (C) 2006-2016 Talend Inc. - www.talend.com
 * 
 * This source code is available under agreement available at
 * %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
 * 
 * You should have received a copy of the agreement along with this program; if not, write to Talend SA 9 rue Pages
 * 92150 Suresnes, France
 */

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    public static Number getDecimalValue(String value, Object franctionDigits) {
        if (value == null || "".equals(value)) {
            return null;
        }
        BigDecimal bigdecimal = new BigDecimal(value);
        if (franctionDigits != null && !franctionDigits.equals("")) {
            return bigdecimal.setScale(Integer.parseInt(franctionDigits.toString()), RoundingMode.HALF_UP);
        }
        return bigdecimal.setScale(2, RoundingMode.HALF_UP);
    }
}

Related

  1. getDecimal(double a)
  2. getDecimal(Object[] data, int ordinal)
  3. getDecimal(String clusive, int[] currentDecimal)
  4. getDecimal(String number, BigDecimal def)
  5. getDecimalCoords(Integer degrees, Integer minutes, Integer seconds)
  6. getDecimalValues(String[] values, String dataType)
  7. nullToBigDecimalZero(final Object obj)
  8. nullToZero(BigDecimal decimal)
  9. nullToZero(BigDecimal num)