Search in sources :

Example 56 with BigDecimal

use of java.math.BigDecimal in project jstorm by alibaba.

the class Bytes method toBigDecimal.

/**
     * Converts a byte array to a BigDecimal value
     *
     * @param bytes
     * @param offset
     * @param length
     * @return the char value
     */
public static BigDecimal toBigDecimal(byte[] bytes, int offset, final int length) {
    if (bytes == null || length < SIZEOF_INT + 1 || (offset + length > bytes.length)) {
        return null;
    }
    int scale = toInt(bytes, offset);
    byte[] tcBytes = new byte[length - SIZEOF_INT];
    System.arraycopy(bytes, offset + SIZEOF_INT, tcBytes, 0, length - SIZEOF_INT);
    return new BigDecimal(new BigInteger(tcBytes), scale);
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal)

Example 57 with BigDecimal

use of java.math.BigDecimal in project otter by alibaba.

the class TestMysqlUnsignedInt method insertNumeric.

public static void insertNumeric() throws ClassNotFoundException, SQLException {
    Class.forName("com.mysql.jdbc.Driver");
    Properties from = new Properties();
    from.put("user", "root");
    from.put("password", "root");
    from.put("characterEncoding", "utf8");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/erosa", from);
    PreparedStatement pst = conn.prepareStatement("insert into unsignednumeric(id,id1,id2,id3) values (?,?,?,?)");
    pst.setLong(1, Integer.MAX_VALUE * 2L);
    pst.setLong(2, Integer.MAX_VALUE);
    pst.setBigDecimal(3, new BigDecimal("18446744073709551614"));
    pst.setBigDecimal(4, new BigDecimal("9223372036854775807"));
    pst.executeUpdate();
    pst.close();
    conn.close();
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) BigDecimal(java.math.BigDecimal)

Example 58 with BigDecimal

use of java.math.BigDecimal in project grails-core by grails.

the class ScaleConstraint method processValidate.

/**
     * {@inheritDoc}
     * @see org.grails.validation.AbstractConstraint#processValidate(
     *     java.lang.Object, java.lang.Object, org.springframework.validation.Errors)
     */
@Override
protected void processValidate(Object target, Object propertyValue, Errors errors) {
    BigDecimal bigDecimal;
    BeanWrapper bean = new BeanWrapperImpl(target);
    if (propertyValue instanceof Float) {
        bigDecimal = new BigDecimal(propertyValue.toString());
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal.floatValue());
    } else if (propertyValue instanceof Double) {
        bigDecimal = new BigDecimal(propertyValue.toString());
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal.doubleValue());
    } else if (propertyValue instanceof BigDecimal) {
        bigDecimal = (BigDecimal) propertyValue;
        bigDecimal = getScaledValue(bigDecimal);
        bean.setPropertyValue(getPropertyName(), bigDecimal);
    } else {
        throw new IllegalArgumentException("Unsupported type detected in constraint [" + getName() + "] of property [" + constraintPropertyName + "] of class [" + constraintOwningClass + "]");
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) BigDecimal(java.math.BigDecimal)

Example 59 with BigDecimal

use of java.math.BigDecimal in project gradle by gradle.

the class Amount method doFormat.

private String doFormat() {
    List<Units<Q>> allUnits = units.getUnitsForQuantity();
    BigDecimal base = normalised.abs();
    for (int i = allUnits.size() - 1; i >= 0; i--) {
        Units<Q> candidate = allUnits.get(i);
        if (base.compareTo(candidate.getFactor()) >= 0) {
            BigDecimal scaled = units.scaleTo(value, candidate);
            return formatValue(scaled) + " " + candidate.format(scaled);
        }
    }
    return formatValue(value) + " " + units.format(value);
}
Also used : BigDecimal(java.math.BigDecimal)

Example 60 with BigDecimal

use of java.math.BigDecimal in project grails-core by grails.

the class NotEqualConstraintTests method testCreationWithWrongParameterType.

// testcase for GRAILS-1209
public void testCreationWithWrongParameterType() {
    // property is Float but parameter is BigDecimal
    try {
        getConstraint("testFloat", new BigDecimal("0.0"));
        fail("NotEqualConstraint must throw an exception for parameter with wrong type .");
    } catch (IllegalArgumentException iae) {
    // Great
    }
    // property is String but parameter is Integer
    try {
        getConstraint("testString", 4);
        fail("MinConstraint must throw an exception for parameter with wrong type .");
    } catch (IllegalArgumentException iae) {
    // Great
    }
}
Also used : BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)5274 Test (org.junit.Test)834 BigInteger (java.math.BigInteger)657 Test (org.testng.annotations.Test)626 LocalDate (org.joda.time.LocalDate)409 ArrayList (java.util.ArrayList)393 ResultSet (java.sql.ResultSet)251 MathContext (java.math.MathContext)220 Timestamp (java.sql.Timestamp)211 PreparedStatement (java.sql.PreparedStatement)207 Date (java.util.Date)175 SQLException (java.sql.SQLException)170 HashMap (java.util.HashMap)157 UUID (java.util.UUID)149 Invoice (org.killbill.billing.invoice.api.Invoice)148 List (java.util.List)136 DateTime (org.joda.time.DateTime)132 RoundingMode (java.math.RoundingMode)129 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)104 Session (org.hibernate.Session)96