Java BigDecimal Format formatCents(int cents)

Here you can find the source of formatCents(int cents)

Description

format Cents

License

Open Source License

Declaration

public static String formatCents(int cents) 

Method Source Code

//package com.java2s;
/**//from w  w w.  j a v a2  s.c om
 * This file is part of alf.io.
 *
 * alf.io 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.
 *
 * alf.io 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 alf.io.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.math.BigDecimal;
import static java.math.RoundingMode.*;

public class Main {
    public static final BigDecimal HUNDRED = new BigDecimal("100.00");

    public static String formatCents(int cents) {
        return centsToUnit(cents).toPlainString();
    }

    public static BigDecimal centsToUnit(int cents) {
        return new BigDecimal(cents).divide(HUNDRED, 2, HALF_UP);
    }
}

Related

  1. formatBigDecimal(BigDecimal number, int val)
  2. formatBigDecimal(BigDecimal valor, int decimal)
  3. formatBigDecimal(BigDecimal value, char thousandSep, char decimalPoint, int numDecimals)
  4. formatBigDecimal(String value)
  5. formatBigDecimalWithPrecise(BigDecimal number)
  6. formatCUBRIDNumber(BigDecimal value)
  7. formatDecimal(BigDecimal b)
  8. formatDecimal(BigDecimal num)
  9. formatDecimal(BigDecimal number, int maxFractionDigits, int minFractionDigits)