dvlwj
01/09/2019, 3:47 AMMatch.ceil feature for this, to predict they payment the buyer gonna use.
The problem is for use Match.ceil i need to have the number in float, but then i read this https://stackoverflow.com/a/3730040 , which is telling that a bad one to use float for financial purpose.
What i need to do?
My code is something like this :
val a: Double = valueInput1.toDouble()
val b: Double = 5000.toDouble()
val c = Math.ceil(a/b)*5000
println(c)Shawn
01/09/2019, 3:51 AMdvlwj
01/09/2019, 3:53 AMShawn
01/09/2019, 3:54 AMdvlwj
01/09/2019, 3:54 AMdvlwj
01/09/2019, 3:55 AMBigDecimal and then save it to my Database, but i just worried if my logic is correct or notShawn
01/09/2019, 3:57 AM.toDouble() you lose the precision you would have with BigDecimaldvlwj
01/09/2019, 3:57 AMBigDecimal from the start, but AFAIK Match.ceil only can process Double 😐Shawn
01/09/2019, 3:57 AMMath.ceilShawn
01/09/2019, 3:57 AMShawn
01/09/2019, 3:58 AMBigDecimal provides setScale, which you can use to perform rounding operationsdvlwj
01/09/2019, 3:58 AMdvlwj
01/09/2019, 3:58 AMShawn
01/09/2019, 4:01 AMMath.ceil(), you’d need something that looks kinda like this
val intValue = bigDecimal.setScale(0, RoundingMode.CEILING).intValueExact()Shawn
01/09/2019, 4:02 AMBigDecimal docs. https://developer.android.com/reference/java/math/BigDecimalShawn
01/09/2019, 4:02 AMfun.dvlwj
01/09/2019, 4:20 AM