更新时间:2023-12-03 16:35:46
您可以轻松地将这些值从BigDecimal中舍入为特定精度,也可以同时将其转换为double值. 例如:-
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> val s :BigDecimal = 10.232 s: BigDecimal = 10.232
scala> s.setScale(2,BigDecimal.RoundingMode.HALF_UP).toDouble res1:Double = 10.23//转换为Double
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//正在路由
scala> s.setScale(2, BigDecimal.RoundingMode.HALF_UP) res2: scala.math.BigDecimal = 10.23 // Rouding Off
因此在scala中,而不是使用math.Round,您可以使用setScale.
So in scala instead of using math.Round you can use setScale.