本文整理了Java中java.math.BigDecimal.equals()
方法的一些代码示例,展示了BigDecimal.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.equals()
方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:equals
[英]Returns true if x is a BigDecimal instance and if this instance is equal to this big decimal. Two big decimals are equal if their unscaled value and their scale is equal. For example, 1.0 (1010-1) is not equal to 1.00 (10010-2). Similarly, zero instances are not equal if their scale differs.
[中]如果x是一个BigDecimal实例,并且此实例等于此大小数,则返回true。如果两个大小数的未标度值和标度相等,则它们相等。例如,1.0(1010-1)不等于1.00(10010-2)。同样,如果零实例的比例不同,则零实例也不相等。
代码示例来源:origin: com.h2database/h2
@Override
public boolean equals(Object other) {
// Two BigDecimal objects are considered equal only if they are equal in
// value and scale (thus 2.0 is not equal to 2.00 when using equals;
// however -0.0 and 0.0 are). Can not use compareTo because 2.0 and 2.00
// have different hash codes
return other instanceof ValueDecimal &&
value.equals(((ValueDecimal) other).value);
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public Comparable<?> getResult() {
if (null == count || BigDecimal.ZERO.equals(count)) {
return count;
}
// TODO 通过metadata获取数据库的浮点数精度值
return sum.divide(count, 4, BigDecimal.ROUND_HALF_UP);
}
}
代码示例来源:origin: stackoverflow.com
new BigDecimal( "0" ).equals( BigDecimal.ZERO) // true
new BigDecimal( "0.00" ).equals( BigDecimal.ZERO) // false!
代码示例来源:origin: graphql-java/graphql-java
@Override
public boolean isEqualTo(Node o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FloatValue that = (FloatValue) o;
return !(value != null ? !value.equals(that.value) : that.value != null);
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
BigDecimalHolder that = (BigDecimalHolder) o;
return this.value == null
? that.value == null
: this.value.equals( that.value );
}
代码示例来源:origin: openhab/openhab1-addons
@Override
public String toString() {
StringBuilder sb = new StringBuilder(latitude.toPlainString());
sb.append(',');
sb.append(longitude.toPlainString());
if (!altitude.equals(BigDecimal.ZERO)) {
sb.append(',');
sb.append(altitude.toPlainString());
}
return sb.toString();
}
代码示例来源:origin: hibernate/hibernate-orm
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MonetaryAmount)) return false;
final MonetaryAmount monetaryAmount = (MonetaryAmount) o;
if (!currency.equals(monetaryAmount.currency)) return false;
if (!value.equals(monetaryAmount.value)) return false;
return true;
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toScaledBigDecimal(BigDecimal)}.
*/
@Test
public void testToScaledBigDecimalBigDecimal() {
assertTrue("toScaledBigDecimal(BigDecimal) 1 failed",
NumberUtils.toScaledBigDecimal(BigDecimal.valueOf(123.456)).equals(BigDecimal.valueOf(123.46)));
// Test RoudingMode.HALF_EVEN default rounding.
assertTrue("toScaledBigDecimal(BigDecimal) 2 failed",
NumberUtils.toScaledBigDecimal(BigDecimal.valueOf(23.515)).equals(BigDecimal.valueOf(23.52)));
assertTrue("toScaledBigDecimal(BigDecimal) 3 failed",
NumberUtils.toScaledBigDecimal(BigDecimal.valueOf(23.525)).equals(BigDecimal.valueOf(23.52)));
assertTrue("toScaledBigDecimal(BigDecimal) 4 failed",
NumberUtils.toScaledBigDecimal(BigDecimal.valueOf(23.525))
.multiply(BigDecimal.valueOf(100)).toString()
.equals("2352.00"));
assertTrue("toScaledBigDecimal(BigDecimal) 5 failed",
NumberUtils.toScaledBigDecimal((BigDecimal) null).equals(BigDecimal.ZERO));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toScaledBigDecimal(Double)}.
*/
@Test
public void testToScaledBigDecimalDouble() {
assertTrue("toScaledBigDecimal(Double) 1 failed",
NumberUtils.toScaledBigDecimal(Double.valueOf(123.456d)).equals(BigDecimal.valueOf(123.46)));
// Test RoudingMode.HALF_EVEN default rounding.
assertTrue("toScaledBigDecimal(Double) 2 failed",
NumberUtils.toScaledBigDecimal(Double.valueOf(23.515d)).equals(BigDecimal.valueOf(23.52)));
assertTrue("toScaledBigDecimal(Double) 3 failed",
NumberUtils.toScaledBigDecimal(Double.valueOf(23.525d)).equals(BigDecimal.valueOf(23.52)));
assertTrue("toScaledBigDecimal(Double) 4 failed",
NumberUtils.toScaledBigDecimal(Double.valueOf(23.525d))
.multiply(BigDecimal.valueOf(100)).toString()
.equals("2352.00"));
assertTrue("toScaledBigDecimal(Double) 5 failed",
NumberUtils.toScaledBigDecimal((Double) null).equals(BigDecimal.ZERO));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toScaledBigDecimal(BigDecimal, int, RoundingMode)}.
*/
@Test
public void testToScaledBigDecimalBigDecimalIRM() {
assertTrue("toScaledBigDecimal(BigDecimal, int, RoudingMode) 1 failed",
NumberUtils.toScaledBigDecimal(BigDecimal.valueOf(123.456), 1, RoundingMode.CEILING).equals(BigDecimal.valueOf(123.5)));
assertTrue("toScaledBigDecimal(BigDecimal, int, RoudingMode) 2 failed",
NumberUtils.toScaledBigDecimal(BigDecimal.valueOf(23.5159), 3, RoundingMode.FLOOR).equals(BigDecimal.valueOf(23.515)));
assertTrue("toScaledBigDecimal(BigDecimal, int, RoudingMode) 3 failed",
NumberUtils.toScaledBigDecimal(BigDecimal.valueOf(23.525), 2, RoundingMode.HALF_UP).equals(BigDecimal.valueOf(23.53)));
assertTrue("toScaledBigDecimal(BigDecimal, int, RoudingMode) 4 failed",
NumberUtils.toScaledBigDecimal(BigDecimal.valueOf(23.521), 4, RoundingMode.HALF_EVEN)
.multiply(BigDecimal.valueOf(1000))
.toString()
.equals("23521.0000"));
assertTrue("toScaledBigDecimal(BigDecimal, int, RoudingMode) 5 failed",
NumberUtils.toScaledBigDecimal((BigDecimal) null, 2, RoundingMode.HALF_UP).equals(BigDecimal.ZERO));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toScaledBigDecimal(Double, int, RoundingMode)}.
*/
@Test
public void testToScaledBigDecimalDoubleIRM() {
assertTrue("toScaledBigDecimal(Double, int, RoudingMode) 1 failed",
NumberUtils.toScaledBigDecimal(Double.valueOf(123.456d), 1, RoundingMode.CEILING).equals(BigDecimal.valueOf(123.5)));
assertTrue("toScaledBigDecimal(Double, int, RoudingMode) 2 failed",
NumberUtils.toScaledBigDecimal(Double.valueOf(23.5159d), 3, RoundingMode.FLOOR).equals(BigDecimal.valueOf(23.515)));
assertTrue("toScaledBigDecimal(Double, int, RoudingMode) 3 failed",
NumberUtils.toScaledBigDecimal(Double.valueOf(23.525d), 2, RoundingMode.HALF_UP).equals(BigDecimal.valueOf(23.53)));
assertTrue("toScaledBigDecimal(Double, int, RoudingMode) 4 failed",
NumberUtils.toScaledBigDecimal(Double.valueOf(23.521d), 4, RoundingMode.HALF_EVEN)
.multiply(BigDecimal.valueOf(1000))
.toString()
.equals("23521.0000"));
assertTrue("toScaledBigDecimal(Double, int, RoudingMode) 5 failed",
NumberUtils.toScaledBigDecimal((Double) null, 2, RoundingMode.HALF_UP).equals(BigDecimal.ZERO));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toScaledBigDecimal(Float, int, RoundingMode)}.
*/
@Test
public void testToScaledBigDecimalFloatIRM() {
assertTrue("toScaledBigDecimal(Float, int, RoudingMode) 1 failed",
NumberUtils.toScaledBigDecimal(Float.valueOf(123.456f), 1, RoundingMode.CEILING).equals(BigDecimal.valueOf(123.5)));
assertTrue("toScaledBigDecimal(Float, int, RoudingMode) 2 failed",
NumberUtils.toScaledBigDecimal(Float.valueOf(23.5159f), 3, RoundingMode.FLOOR).equals(BigDecimal.valueOf(23.515)));
// The following happens due to roundoff error. We're ok with this.
assertTrue("toScaledBigDecimal(Float, int, RoudingMode) 3 failed",
NumberUtils.toScaledBigDecimal(Float.valueOf(23.525f), 2, RoundingMode.HALF_UP).equals(BigDecimal.valueOf(23.52)));
assertTrue("toScaledBigDecimal(Float, int, RoudingMode) 4 failed",
NumberUtils.toScaledBigDecimal(Float.valueOf(23.521f), 4, RoundingMode.HALF_EVEN)
.multiply(BigDecimal.valueOf(1000))
.toString()
.equals("23521.0000"));
assertTrue("toScaledBigDecimal(Float, int, RoudingMode) 5 failed",
NumberUtils.toScaledBigDecimal((Float) null, 2, RoundingMode.HALF_UP).equals(BigDecimal.ZERO));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toScaledBigDecimal(Double, int, RoundingMode)}.
*/
@Test
public void testToScaledBigDecimalStringIRM() {
assertTrue("toScaledBigDecimal(String, int, RoudingMode) 1 failed",
NumberUtils.toScaledBigDecimal("123.456", 1, RoundingMode.CEILING).equals(BigDecimal.valueOf(123.5)));
assertTrue("toScaledBigDecimal(String, int, RoudingMode) 2 failed",
NumberUtils.toScaledBigDecimal("23.5159", 3, RoundingMode.FLOOR).equals(BigDecimal.valueOf(23.515)));
assertTrue("toScaledBigDecimal(String, int, RoudingMode) 3 failed",
NumberUtils.toScaledBigDecimal("23.525", 2, RoundingMode.HALF_UP).equals(BigDecimal.valueOf(23.53)));
assertTrue("toScaledBigDecimal(String, int, RoudingMode) 4 failed",
NumberUtils.toScaledBigDecimal("23.521", 4, RoundingMode.HALF_EVEN)
.multiply(BigDecimal.valueOf(1000))
.toString()
.equals("23521.0000"));
assertTrue("toScaledBigDecimal(String, int, RoudingMode) 5 failed",
NumberUtils.toScaledBigDecimal((String) null, 2, RoundingMode.HALF_UP).equals(BigDecimal.ZERO));
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toScaledBigDecimal(Double)}.
*/
@Test
public void testToScaledBigDecimalString() {
assertTrue("toScaledBigDecimal(String) 1 failed",
NumberUtils.toScaledBigDecimal("123.456").equals(BigDecimal.valueOf(123.46)));
// Test RoudingMode.HALF_EVEN default rounding.
assertTrue("toScaledBigDecimal(String) 2 failed",
NumberUtils.toScaledBigDecimal("23.515").equals(BigDecimal.valueOf(23.52)));
assertTrue("toScaledBigDecimal(String) 3 failed",
NumberUtils.toScaledBigDecimal("23.525").equals(BigDecimal.valueOf(23.52)));
assertTrue("toScaledBigDecimal(String) 4 failed",
NumberUtils.toScaledBigDecimal("23.525")
.multiply(BigDecimal.valueOf(100)).toString()
.equals("2352.00"));
assertTrue("toScaledBigDecimal(String) 5 failed",
NumberUtils.toScaledBigDecimal((String) null).equals(BigDecimal.ZERO));
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public boolean equals(Object x, Object y) throws HibernateException {
if (!(x instanceof DollarValue) || !(y instanceof DollarValue)) {
throw new HibernateException("Expected DollarValue");
}
return ((DollarValue)x).getAmount().equals(((DollarValue)y).getAmount());
}
代码示例来源:origin: hibernate/hibernate-orm
public boolean equals(Object x, Object y) throws HibernateException {
if ( x == y ) return true;
if ( x == null || y == null ) return false;
MonetaryAmount mx = (MonetaryAmount) x;
MonetaryAmount my = (MonetaryAmount) y;
return mx.getAmount().equals( my.getAmount() ) &&
mx.getCurrency().equals( my.getCurrency() );
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public boolean equals(Object x, Object y) throws HibernateException {
if (x==y) return true;
if (x==null || y==null) return false;
MonetoryAmount mx = (MonetoryAmount) x;
MonetoryAmount my = (MonetoryAmount) y;
return mx.getAmount().equals( my.getAmount() ) &&
mx.getCurrency().equals( my.getCurrency() );
}
代码示例来源:origin: hibernate/hibernate-orm
public boolean equals(Object x, Object y) throws HibernateException {
if ( x == y ) return true;
if ( x == null || y == null ) return false;
MonetaryAmount mx = (MonetaryAmount) x;
MonetaryAmount my = (MonetaryAmount) y;
return mx.getAmount().equals( my.getAmount() ) &&
mx.getCurrency().equals( my.getCurrency() );
}
代码示例来源:origin: spring-projects/spring-framework
assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2")));
assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2()));
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal")));
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal()));
代码示例来源:origin: spring-projects/spring-framework
assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2")));
assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2()));
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal")));
assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal()));
内容来源于网络,如有侵权,请联系作者删除!