Package java.math

Examples of java.math.BigDecimal.toBigInteger()


            catch (NumberFormatException e)
            {
                try
                {
                    BigDecimal n = new BigDecimal(s);
                    BigInteger i = n.toBigInteger();

                    int gt = i.compareTo(INTMAX);
                    int lt = i.compareTo(INTMIN);

                    if (gt > 0 || lt < 0)
View Full Code Here


            catch (NumberFormatException e)
            {
                try
                {
                    BigDecimal n = new BigDecimal(s);
                    BigInteger i = n.toBigInteger();
                    int gt = i.compareTo(LONGMAX);
                    int lt = i.compareTo(LONGMIN);

                    if ( gt > 0 || lt < 0 )
                    {
View Full Code Here

            }
        }
        else if (value instanceof BigDecimal)
        {
            BigDecimal bd = (BigDecimal) value;
            return bd.toBigInteger();
        }
        else if (value instanceof Boolean)
        {
            return new BigInteger(((Boolean) value) ? "1" : "0");
        }
View Full Code Here

            // System.out.println("Ints: \t" + hexi);
            // assertEquals("Should be " + hexb, hexb, hexi);

            BigDecimal numeric = new BigDecimal(new BigInteger(bytes));

            BigInteger nvalue = numeric.toBigInteger();

            long lsb_bi = nvalue.longValue(); // low-order 8 bytes out (first 64bit)
            long msb_bi = nvalue.shiftRight(8 * 8).longValue(); // most sognificant 8 bytes out (last
            // 64bit)
            // String hexbi = Long.toHexString(msb_bi) + Long.toHexString(lsb_bi) ;
View Full Code Here

            } else if (type == BigDecimal.class) {
                return new BigDecimal(n.toString());
            } else if (type == BigInteger.class) {
                if (object instanceof Float || object instanceof Double) {
                    BigDecimal bd = new BigDecimal(n.doubleValue());
                    return bd.toBigInteger();
                } else if (object instanceof BigDecimal) {
                    return ((BigDecimal) object).toBigInteger();
                } else {
                    return new BigInteger(n.toString());
                }
View Full Code Here

    // segment to be replaced:
    final BigDecimal secondsValue = secondsValue();   
    final BigDecimal m = secondsValue.divide(SIXTY_DECIMAL, 0, BigDecimal.ROUND_DOWN);
    seconds = nullIfZero(secondsValue.subtract(SIXTY_DECIMAL.multiply(m)))
    r = m.toBigInteger().divideAndRemainder(SIXTY);   
   
    minutes = nullIfZero(r[1]);
    r = r[0].divideAndRemainder(TWENTY_FOUR);
    hours = nullIfZero(r[1]);
    days = nullIfZero(r[0]);
View Full Code Here

  public void testToBigIntegerNeg1() {
    String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
    BigInteger bNumber = new BigInteger(
        "-123809648392384754573567356745735635678902957849027687");
    BigDecimal aNumber = new BigDecimal(a);
    BigInteger result = aNumber.toBigInteger();
    assertTrue("incorrect value", result.equals(bNumber));
  }

  /**
   * Convert a negative BigDecimal to BigInteger.
View Full Code Here

  public void testToBigIntegerNeg2() {
    String a = "-123809648392384754573567356745735.63567890295784902768787678287E+15";
    BigInteger bNumber = new BigInteger(
        "-123809648392384754573567356745735635678902957849");
    BigDecimal aNumber = new BigDecimal(a);
    BigInteger result = aNumber.toBigInteger();
    assertTrue("incorrect value", result.equals(bNumber));
  }

  /**
   * Convert a negative BigDecimal to BigInteger.
View Full Code Here

  public void testToBigIntegerNeg3() {
    String a = "-123809648392384754573567356745735.63567890295784902768787678287E+45";
    BigInteger bNumber = new BigInteger(
        "-123809648392384754573567356745735635678902957849027687876782870000000000000000");
    BigDecimal aNumber = new BigDecimal(a);
    BigInteger result = aNumber.toBigInteger();
    assertTrue("incorrect value", result.equals(bNumber));
  }

  /**
   * Convert a positive BigDecimal to BigInteger.
View Full Code Here

  public void testToBigIntegerPos1() {
    String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
    BigInteger bNumber = new BigInteger(
        "123809648392384754573567356745735635678902957849027687");
    BigDecimal aNumber = new BigDecimal(a);
    BigInteger result = aNumber.toBigInteger();
    assertTrue("incorrect value", result.equals(bNumber));
  }

  /**
   * Convert a positive BigDecimal to BigInteger.
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.