Format number using decimal format in kotlin

后端 未结 4 768
渐次进展
渐次进展 2021-01-17 11:46

I am facing an issue where I need to do some calculations with a number like for example 5000,00 multiplied it by (1,025^3).

So in

4条回答
  •  时光说笑
    2021-01-17 12:06

    val num = 1.34567
    val df = DecimalFormat("#.##")
    df.roundingMode = RoundingMode.CEILING
    
    println(df.format(num))
    

    When you run the program, the output will be: 1.34

    Check: https://www.programiz.com/kotlin-programming/examples/round-number-decimal

提交回复
热议问题