Java BigDecimal to toUnsignedString(BigDecimal bigDecimal, int shift)

Here you can find the source of toUnsignedString(BigDecimal bigDecimal, int shift)

Description

to Unsigned String

License

Open Source License

Declaration

public static String toUnsignedString(BigDecimal bigDecimal, int shift) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

import java.util.*;

public class Main {
    final static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
            'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
            'w', 'x', 'y', 'z' };

    public static String toUnsignedString(BigDecimal bigDecimal, int shift) {
        BigDecimal divisor = new BigDecimal(shift);
        Deque<Character> numberDeque = new ArrayDeque<Character>();
        do {//www . ja va 2  s .  c  o m
            BigDecimal[] ba = bigDecimal.divideAndRemainder(divisor);
            bigDecimal = ba[0];
            numberDeque.addFirst(digits[ba[1].intValue()]);
        } while (bigDecimal.compareTo(BigDecimal.ZERO) > 0);
        StringBuilder builder = new StringBuilder();
        for (Character character : numberDeque) {
            builder.append(character);
        }
        return builder.toString();
    }
}

Related

  1. toScientificNotation(BigDecimal bd)
  2. toSimpleBigDecimal(Object num)
  3. toString(BigDecimal num)
  4. toString(BigDecimal value, int numberDecimalPlaces)
  5. toString(final BigDecimal dec)