consider below method:
fun main() {
var costs = 0
var transactionFee = 1.325
var total = (costs + transactionFee).toRoundedUpDouble()
}
fun Double.toRoundedUpDouble(fraction: Int = 2) =
BigDecimal(this).setScale(fraction, RoundingMode.HALF_UP).toDouble()
I want a number with 2 decimal after the comma, rounded up from 5. e.g. 1.325 becomes 1.33. This works when I add a round number, but not when I don't:
Output:
5.00 + 1.325 becomes 6.33 = good
5 + 1.325 becomes 6.33 = good
1 + 1.325 becomes 2.33 = good
1.325 becomes 1.32 = NOT GOOD
0 + 1.325 becomes 1.32 = NOT GOOD
0.00 + 1.325 becomes 1.32 = NOT GOOD
0.000 + 1.325 becomes 1.32 = NOT GOOD
This thread doesn't answer my question.