Java BigInteger Calculate normalizarParaBigInteger(Number numero, RoundingMode modo)

Here you can find the source of normalizarParaBigInteger(Number numero, RoundingMode modo)

Description

normalizar Para Big Integer

License

Open Source License

Declaration

public static BigInteger normalizarParaBigInteger(Number numero, RoundingMode modo) throws ArithmeticException 

Method Source Code


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

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

public class Main {
    public static BigInteger normalizarParaBigInteger(Number numero, RoundingMode modo) throws ArithmeticException {
        BigInteger valor;//from  w  w  w  . j  ava  2s.c o  m

        if (numero instanceof BigDecimal) {
            if (modo != null) {
                valor = ((BigDecimal) numero).divide(BigDecimal.ONE, modo).toBigIntegerExact();

            } else {
                valor = ((BigDecimal) numero).toBigIntegerExact();
            }

        } else if (numero instanceof Double) {
            BigDecimal bd = BigDecimal.valueOf((double) numero);

            if (modo != null) {
                valor = bd.divide(BigDecimal.ONE, modo).toBigIntegerExact();

            } else {
                valor = bd.toBigIntegerExact();
            }

        } else if (numero instanceof Float) {
            BigDecimal bd = BigDecimal.valueOf((float) numero);

            if (modo != null) {
                valor = bd.divide(BigDecimal.ONE, modo).toBigIntegerExact();

            } else {
                valor = bd.toBigIntegerExact();
            }

        } else if (numero instanceof BigInteger) {
            valor = (BigInteger) numero;

        } else {
            valor = BigInteger.valueOf(numero.longValue());
        }

        return valor;
    }

    public static BigInteger normalizarParaBigInteger(Number numero) {
        return normalizarParaBigInteger(numero, null);
    }
}

Related

  1. mods(BigInteger v, BigInteger m)
  2. modulus(BigInteger value, BigInteger divider, int modulo, int... weight)
  3. multi_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus)
  4. multiply(BigInteger x, BigInteger y)
  5. negative(BigInteger n)
  6. numberToIpv4(BigInteger ipNumber)
  7. numberToShortString(BigInteger number)
  8. order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[])
  9. parseBigInteger(String s, BigInteger defaultValue)