Here you can find the source of unformattedToBigDecimal(String str)
BigDecimal
.
Parameter | Description |
---|---|
str | The string to convert. |
BigDecimal
public static BigDecimal unformattedToBigDecimal(String str)
//package com.java2s; /*// w w w . java 2 s.c om * Copyright (C) 2015 Miquel Sas * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. */ import java.math.BigDecimal; public class Main { /** * Convert an unformatted string to <code>BigDecimal</code>. * * @return A <code>BigDecimal</code> * @param str The string to convert. */ public static BigDecimal unformattedToBigDecimal(String str) { if (str == null || str.length() == 0) { str = "0"; } BigDecimal b = new BigDecimal(str); return b.setScale(b.scale(), BigDecimal.ROUND_HALF_UP); } }