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);
}
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();
}
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 + "]");
}
}
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);
}
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
}
}
Aggregations