Java BigInteger Calculate extractFloat(BigInteger bi, int start, int end, int decimal)

Here you can find the source of extractFloat(BigInteger bi, int start, int end, int decimal)

Description

extract Float

License

Open Source License

Declaration

public static float extractFloat(BigInteger bi, int start, int end, int decimal) 

Method Source Code


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

public class Main {
    public static float extractFloat(BigInteger bi, int start, int end, int decimal) {
        int intpart = extractInt(bi, start + decimal, end);
        int decpart = extractInt(bi, start, start + decimal);
        float decf = decpart;
        while (decf >= 1.0) {
            decf = decf / 10;/*from w w w.j a  v  a  2 s .  com*/
        }
        float ret = intpart + decf;
        return ret;
    }

    public static int extractInt(BigInteger bi, int start, int end) {
        bi = bi.shiftRight(start);
        int foo = (int) Math.pow(2, end - start) - 1;
        BigInteger mask = BigInteger.valueOf(foo);
        bi = bi.and(mask);
        return bi.intValue();
    }
}

Related

  1. encodeToString(final BigInteger input)
  2. encodeURL(BigInteger id)
  3. equal(BigInteger int1, BigInteger int2)
  4. equals(BigInteger[] a, BigInteger[] b)
  5. extractBoolean(BigInteger bi, int index)
  6. extractInt(BigInteger bi, int start, int end)
  7. fill(BigInteger[] array, BigInteger value)
  8. first(BigInteger i, BigInteger j)
  9. firstLtSecond(BigInteger first, BigInteger second)