Package java.math

Examples of java.math.BigDecimal.toBigIntegerExact()


            CorruptIndexException e = new CorruptIndexException("failed to parse BigDecimal value (resource=" + in + ")");
            e.initCause(pe);
            throw e;
          }
          SimpleTextUtil.readLine(in, scratch); // read the line telling us if its real or not
          return BigInteger.valueOf(field.minValue).add(bd.toBigIntegerExact()).longValue();
        } catch (IOException ioe) {
          throw new RuntimeException(ioe);
        }
      }
    };
View Full Code Here


     */
    public void testToBigIntegerExact1() {
        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+45";
        BigDecimal aNumber = new BigDecimal(a);
        String res = "-123809648392384754573567356745735635678902957849027687876782870000000000000000";
        BigInteger result = aNumber.toBigIntegerExact();
        assertEquals("incorrect value", res, result.toString());
    }

    /**
     * toBigIntegerExact()
 
View Full Code Here

     */
    public void testToBigIntegerExactException() {
        String a = "-123809648392384754573567356745735.63567890295784902768787678287E-10";
        BigDecimal aNumber = new BigDecimal(a);
        try {
            aNumber.toBigIntegerExact();
            fail("java.lang.ArithmeticException has not been thrown");
        } catch (java.lang.ArithmeticException e) {
            return;
        }
    }
View Full Code Here

    @Test
    public void testToBigIntegerExact1() {
        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+45";
        BigDecimal aNumber = new BigDecimal(a);
        String res = "-123809648392384754573567356745735635678902957849027687876782870000000000000000";
        BigInteger result = aNumber.toBigIntegerExact();
        assertEquals("incorrect value", res, result.toString());
    }

    /**
     * toBigIntegerExact()
 
View Full Code Here

    @Test
    public void testToBigIntegerExactException() {
        String a = "-123809648392384754573567356745735.63567890295784902768787678287E-10";
        BigDecimal aNumber = new BigDecimal(a);
        try {
            aNumber.toBigIntegerExact();
            fail("java.lang.ArithmeticException has not been thrown");
        } catch (java.lang.ArithmeticException e) {
            return;
        }
    }
View Full Code Here

        }
        BigDecimal number = new BigDecimal(numberString.toUpperCase());
        try
        {
            // TODO - doesn't cope with unsigned longs > Long.MAX_VALUE
            BigInteger bigInteger = number.toBigIntegerExact();
            if(bigInteger.longValue() > Integer.MAX_VALUE
                    || bigInteger.longValue() < Integer.MIN_VALUE)
            {
                return new Token(TokenType.NUMBER, bigInteger.longValue());
            }
View Full Code Here

        }
      } else {
        BigDecimal bigDec = json.getAsBigDecimal();
       
        try {
          bigDec.toBigIntegerExact();
         
          try {
            return bigDec.intValueExact();
          } catch (ArithmeticException e) {
            return bigDec.longValue();
View Full Code Here

            return ret;
        }

        final BigDecimal decimal = node.decimalValue();
        ret.put(keyword, decimal.scale() == 0
            ? FACTORY.numberNode(decimal.toBigIntegerExact())
            : node);

        return ret;
    }
}
View Full Code Here

            returnType));
      }
    } else {
      try {
        if (returnType.isAssignableFrom(BigInteger.class)) {
          return returnType.cast(valueBigDecimal.toBigIntegerExact());
        } else if (returnType.isAssignableFrom(Long.class)) {
          return returnType.cast(valueBigDecimal.longValueExact());
        } else if (returnType.isAssignableFrom(Integer.class)) {
          return returnType.cast(valueBigDecimal.intValueExact());
        } else if (returnType.isAssignableFrom(Short.class)) {
View Full Code Here

                        IntNum den = value.denominator();
                        BigDecimal nums = new BigSquareRoot().get(num.asBigDecimal());
                        BigDecimal dens = new BigSquareRoot().get(den.asBigDecimal());
                        try {
                            num = IntNum.valueOf(nums.toBigIntegerExact().toString());
                            den = IntNum.valueOf(dens.toBigIntegerExact().toString());
                            return context.runtime.newNumber(new IntFraction(num, den));
                        } catch(ArithmeticException e) {
                            // Ignore and fall through
                        }
                    }
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.