find BigInteger Nearest Power Of Ten - Java java.math

Java examples for java.math:BigInteger

Description

find BigInteger Nearest Power Of Ten

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        BigInteger bint = new BigInteger("1234");
        System.out.println(findNearestPowerOfTen(bint));
    }/*from w ww .  ja  va2 s . co m*/

    public static BigInteger findNearestPowerOfTen(BigInteger bint) {
        BigInteger divisor = BigInteger.ONE;

        int length = bint.toString().length();
        for (int i = 0; i < length - 1; i++) {
            divisor = divisor.multiply(BigInteger.TEN);
        }

        return divisor;
    }
}

Related Tutorials