Here you can find the source of getDecimal(String clusive, int[] currentDecimal)
private static void getDecimal(String clusive, int[] currentDecimal)
//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; } } } }