Rounding to 2 decimal places in mongodb

后端 未结 1 857
-上瘾入骨i
-上瘾入骨i 2021-01-22 04:34

I have my collection as

Student

{
    \"first_name\":\"Harew\",
    \"last_name\":\"Jackson\",
    \"class\":14,
    \"fee\": [
                 


        
相关标签:
1条回答
  • 2021-01-22 05:10

    you can easily round up the values into specific precision from BigDecimal , also if you want you can convert it into double value at the same time . For Example : -

    scala> val s :BigDecimal = 10.232 s: BigDecimal = 10.232

    scala> s.setScale(2, BigDecimal.RoundingMode.HALF_UP).toDouble res1: Double = 10.23 // CONVERTED AS DOUBLE

    scala> s.setScale(2, BigDecimal.RoundingMode.HALF_UP) res2: scala.math.BigDecimal = 10.23 // Rouding Off

    So in scala instead of using math.Round you can use setScale.

    0 讨论(0)
提交回复
热议问题