big Decimal To String - Java java.math

Java examples for java.math:BigDecimal Convert

Description

big Decimal To String

Demo Code


//package com.java2s;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] argv) throws Exception {
        BigDecimal amount = new BigDecimal("1234");
        System.out.println(bigDecimalToString(amount));
    }/*from ww  w  . j a  v  a2 s.com*/

    public static String bigDecimalToString(BigDecimal amount) {
        String strAmount = "$";
        if (amount.signum() == -1) {
            strAmount += "(" + amount.abs().toPlainString() + ")";
        } else {
            strAmount += amount.abs().toPlainString();
        }
        return strAmount;
    }
}

Related Tutorials