Here you can find the source of getSignedBalance(BigDecimal balance)
Parameter | Description |
---|---|
balance | Balance for which a sign must be added |
public static String getSignedBalance(BigDecimal balance)
//package com.java2s; /*//w ww . j a v a2 s .c o m * Utilities.java * * Copyright (C) 2009 Francois Duchemin * * This file is part of GrisbiGraphs. * * GrisbiGraphs 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 2 of the License, or * (at your option) any later version. * * GrisbiGraphs 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 GrisbiGraphs; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import java.math.BigDecimal; import java.math.RoundingMode; public class Main { /** * Utility method to add a sign to a balance<BR/> * getSignedBalance(100) returns "+100"<BR/> * getSignedBalance(-100) returns "-100"<BR/> * getSignedBalance(0) returns "0" * @param balance Balance for which a sign must be added * @return Signed balance as string */ public static String getSignedBalance(BigDecimal balance) { String signedBalance = ""; if (balance.compareTo(BigDecimal.ZERO) > 0) { signedBalance += "+"; } signedBalance += balance.setScale(2, RoundingMode.HALF_EVEN).toString(); return signedBalance; } }