Java Utililty Methods BigDecimal Format

List of utility methods to do BigDecimal Format

Description

The list of methods to do BigDecimal Format are organized into topic(s).

Method

StringformatRight(BigDecimal pNombre, NumberFormat pNf, int pMaxNumberOfDigit)
format Right
StringBuffer buf = new StringBuffer();
FieldPosition fpos = new FieldPosition(NumberFormat.INTEGER_FIELD);
pNf.format(pNombre, buf, fpos);
for (int i = 0; i < pMaxNumberOfDigit - fpos.getEndIndex(); ++i) {
    buf.insert(0, ' ');
return buf.toString();
StringformatServiceSpecificDate(Date date)
Formats the give date object into an KSC Service format.
if (date == null)
    return null;
BigDecimal dateValue = BigDecimal.valueOf(date.getTime());
return dateValue.scaleByPowerOfTen(0 - KSC_DATE_MILLI_SECOND_PRECISION).toPlainString();
StringformatSize(Integer size)
format Size
String formattedFileSize = "";
if (size != null) {
    BigDecimal kb = BigDecimal.valueOf(1024);
    BigDecimal mb = BigDecimal.valueOf(1048576);
    BigDecimal fileSizeBD = BigDecimal.valueOf(size);
    if (size > 999999) {
        formattedFileSize = fileSizeBD.divide(mb, 2, RoundingMode.HALF_UP).toPlainString();
        formattedFileSize += " MB";
...
StringformatStore(long store)
format Store
if (store > TB) {
    double mem = divider(store, TB, 2);
    return new StringBuilder(String.valueOf(mem)).append(" ").append("TB").toString();
} else if (store > GB) {
    double mem = divider(store, GB, 2);
    return new StringBuilder(String.valueOf(mem)).append(" ").append("GB").toString();
} else if (store > MB) {
    double mem = divider(store, MB, 2);
...
StringformattedFromBigDecimal(BigDecimal number, int scale, Locale locale)
Convert from a BigDecimal forcing the scale.
NumberFormat formatted = NumberFormat.getNumberInstance(locale);
formatted.setMaximumFractionDigits(scale);
formatted.setMinimumFractionDigits(scale);
return formatted.format(number.doubleValue());
BigDecimalformattedToBigDecimal(String str, Locale locale)
Convert to BigDecimal from a formatted string.
if (str.length() == 0) {
    str = "0";
return new BigDecimal(NumberFormat.getNumberInstance(locale).parse(str).toString());
StringformatTime(BigDecimal seconds)
format Time
int whole = seconds.intValue();
BigDecimal frac = seconds.subtract(new BigDecimal(whole));
int f = frac.multiply(new BigDecimal(1000)).intValue();
int m = whole / 60;
int s = whole % 60;
int h = m / 60;
m = m % 60;
return String.format(TIME_FORMAT, h, m, s, f);
...
floatformatTwoDecimals(float num)
format Two Decimals
BigDecimal bg = new BigDecimal(num);
float f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
return f1;
StringformatUnwithE(Object arg)
DOC Administrator Comment method "formatUnwithE".
String doubleString = String.valueOf(arg);
int index = doubleString.indexOf("E");
if (index != -1) {
    return (new BigDecimal(doubleString)).toPlainString();
return doubleString;
intformatYuan2Fen(double fee)
format Yuan Fen
BigDecimal _fee = new BigDecimal(Double.toString(fee));
return _fee.multiply(new BigDecimal("100")).setScale(0, BigDecimal.ROUND_HALF_EVEN).intValue();