I have the following code:
import java.math.RoundingMode
fun fValueNettoBase(priceNetto:Double , quantity:Double) = dRound(priceNetto * quantity, 2)
fun dRound(double: Double, nrOfDec: Int = 2): Double =
double.toBigDecimal().setScale(nrOfDec, RoundingMode.HALF_UP).toDouble()
fun main() {
val quantity = 1.38
val price = 3.25
println("${fValueNettoBase(price,quantity)}")
}
it is rounded incorrectly to 4.48 instead of 4.49, any ideas why? My gut feel is it has to do with the conversion from double to big decimal and the other way round, but I'm not sure how to make it work