Java BigDecimal Create getDecimal(String clusive, int[] currentDecimal)

Here you can find the source of getDecimal(String clusive, int[] currentDecimal)

Description

get Decimal

License

Open Source License

Declaration

private static void getDecimal(String clusive, int[] currentDecimal) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright ? 2011, 2013 IBM Corporation and others.
 * 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://from  w w w .ja v  a2s  .c o  m
 * IBM Corporation - initial API and implementation
 *
 *******************************************************************************/

import java.math.BigDecimal;

public class Main {
    private static void getDecimal(String clusive, int[] currentDecimal) {
        int length = 0;
        int decimal = 0;
        if (clusive != null && clusive.length() > 0) {
            try {
                BigDecimal bd = new BigDecimal(clusive);
                length = (bd.abs().toPlainString().length() + (bd.scale() > 0 ? -1 : 0));
                if (bd.scale() > 0) {
                    decimal = bd.scale();
                }
            } catch (Exception e) {
                int idx = -1;
                if ((clusive.charAt(0) == '-' || clusive.charAt(0) == '+') && clusive.length() > 1) {
                    clusive = clusive.substring(1);
                }
                length = clusive.length();
                idx = clusive.indexOf('.');
                if (idx > -1) {
                    decimal = length - (idx + 1);
                    length = length - decimal;
                }
            }

            if (length > currentDecimal[0]) {
                currentDecimal[0] = length;
            }
            if (decimal > currentDecimal[1]) {
                currentDecimal[1] = decimal;
            }
        }
    }
}

Related

  1. getBigDecimalFromPrimitiveTypes(int input, int scale, int precision)
  2. getBigDecimalOrNull(Object value)
  3. getBigDecimalValue(Object o)
  4. getDecimal(double a)
  5. getDecimal(Object[] data, int ordinal)
  6. getDecimal(String number, BigDecimal def)
  7. getDecimalCoords(Integer degrees, Integer minutes, Integer seconds)
  8. getDecimalValue(String value, Object franctionDigits)
  9. getDecimalValues(String[] values, String dataType)