Package java.math

Examples of java.math.BigDecimal


      }
    });

    {
      Source source = new Source();
      source.bigDecimal = new BigDecimal(1);
      Destination result = mapper.map(source, Destination.class);
      assertThat(result.bigDecimal, equalTo(new Double(1)));
    }

    {
View Full Code Here


  public static SimpleValue wrap(MetaType type, String value) {
    if (type instanceof SimpleMetaType) {
      SimpleMetaType st = (SimpleMetaType)type;
     
      if (SimpleMetaType.BIGDECIMAL.equals(st)) {
        return new SimpleValueSupport(st, new BigDecimal(value));
      } else if (SimpleMetaType.BIGINTEGER.equals(st)) {
        return new SimpleValueSupport(st, new BigInteger(value));
      } else if (SimpleMetaType.BOOLEAN.equals(st)) {
        return new SimpleValueSupport(st, Boolean.valueOf(value));
      } else if (SimpleMetaType.BOOLEAN_PRIMITIVE.equals(st)) {
View Full Code Here

        }
    }
   
    private static class BigDecimalColumnSerializer extends ColumnSerializer {
        protected void writeObject(ObjectOutput out, Object obj) throws IOException {
            BigDecimal val = (BigDecimal)obj;
            out.writeInt(val.scale());
            BigInteger unscaled = val.unscaledValue();
            byte[] bytes = unscaled.toByteArray();
            out.writeInt(bytes.length);
            out.write(bytes);
        }
View Full Code Here

        protected Object readObject(ObjectInput in) throws IOException {
            int scale = in.readInt();
            int length = in.readInt();
            byte[] bytes = new byte[length];
            in.readFully(bytes);
            return new BigDecimal(new BigInteger(bytes), scale);
        }
View Full Code Here

   * @throws TransformationException if value is an incorrect input type or
   * the transformation fails
   */
  public Object transformDirect(Object value) throws TransformationException {
    try {
      return new BigDecimal(((String)value).trim());
    } catch(NumberFormatException e) {
      throw new TransformationException("ERR.003.029.0014", CorePlugin.Util.getString("ERR.003.029.0014", value)); //$NON-NLS-1$ //$NON-NLS-2$
    }
  }
View Full Code Here

    }

    private void insertOrder() throws SQLException {
        PreparedStatement prep = conn.prepareStatement("insert into orders(customer_id , total) values(?, ?)");
        prep.setInt(1, random.nextInt(getCustomerCount()));
        BigDecimal total = new BigDecimal("0");
        prep.setBigDecimal(2, total);
        prep.executeUpdate();
        ResultSet rs = prep.getGeneratedKeys();
        rs.next();
        int orderId = rs.getInt(1);
        int lines = random.nextInt(20);
        for (int i = 0; i < lines; i++) {
            insertLine.setInt(1, orderId);
            insertLine.setInt(2, i);
            insertLine.setString(3, ITEMS[random.nextInt(ITEMS.length)]);
            BigDecimal amount = new BigDecimal(random.nextInt(100) + "." + random.nextInt(10));
            insertLine.setBigDecimal(4, amount);
            total = total.add(amount);
            insertLine.addBatch();
        }
        insertLine.executeBatch();
View Full Code Here

    private void testPrecision() throws SQLException {
        Connection conn = getConnection("functions");
        Statement stat = conn.createStatement();
        stat.execute("create alias no_op for \""+getClass().getName()+".noOp\"");
        PreparedStatement prep = conn.prepareStatement("select * from dual where no_op(1.6)=?");
        prep.setBigDecimal(1, new BigDecimal("1.6"));
        ResultSet rs = prep.executeQuery();
        assertTrue(rs.next());

        stat.execute("create aggregate agg_sum for \""+getClass().getName()+"\"");
        rs = stat.executeQuery("select agg_sum(1), sum(1.6) from dual");
View Full Code Here

    public void add(Object value) {
        // ignore
    }

    public Object getResult() {
        return new BigDecimal("1.6");
    }
View Full Code Here

    }

    // Source = BIGDECIMAL
   
    public void testBigDecimalToString() throws Exception {
        helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "string", "char(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
View Full Code Here

    public void testBigDecimalToString() throws Exception {
        helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "string", "char(1.0)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }

    public void testBigDecimalToBoolean() throws Exception {
        helpTest(LANG_FACTORY.createLiteral(new BigDecimal("1.0"), BigDecimal.class), "boolean", "CASE WHEN 1.0 = 0 THEN 0 WHEN 1.0 IS NOT NULL THEN 1 END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
View Full Code Here

TOP

Related Classes of java.math.BigDecimal

Copyright © 2018 www.massapicom. 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.