Karolis
07/18/2019, 3:25 PMno? val x = BigDecimal.ONE
val y = x.setScale(999)
x == y // => false
x.compareTo(y) == 0 // => trueBob Glamm
07/18/2019, 3:31 PMBigDecimal.ONE.equals(BigDecimal.ONE.setScale(999)) returns false in plain Java, and Kotlin == uses .equals, x==y is false aboveBob Glamm
07/18/2019, 3:31 PMKarolis
07/18/2019, 3:32 PMoperator comparesEqualPavlo Liapota
07/18/2019, 3:36 PMx <= y && x >= y
🧌Karolis
07/18/2019, 3:37 PMLS
07/18/2019, 6:32 PMequals and make it use compareToKarolis
07/18/2019, 6:34 PMcompareEquals or something like thatAl Warren
07/19/2019, 2:49 AMinfix fun BigDecimal.equalsUnscaled(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as BigDecimal
if (compareTo(other) == 0) return true
return false
}
fun main() {
val x = BigDecimal.ONE
val y = x.setScale(5)
println(x)
println(y)
println(x.equalsUnscaled(y))
println(x equalsUnscaled y)
}
// output
// 1
// 1.00000
// true
// trueKarolis
07/19/2019, 5:47 AMMike
07/19/2019, 11:41 AMinfix fun BigDecimal.numericallyEquals(value: BigDecimal) = this.compareTo(value) == 0
This is what my project created for thisMike
07/19/2019, 11:41 AMKarolis
07/19/2019, 11:44 AMMike
07/19/2019, 11:46 AM