经过的时间只有2位数

时间:2022-11-30 11:56:35

So in my scenario i am calculating times between 2 points and want to show this with only 2 decimal points. This is what i have try:

所以在我的场景中,我计算2点之间的时间,并希望仅显示2个小数点。这是我试过的:

import java.util.concurrent._
val startTmp = System.nanoTime
// Do my stuff...
val endTime = System.nanoTime
val elapsedTimeInSecondsTmp = BigDecimal(TimeUnit.MILLISECONDS.convert(
          endTmp - startTmp, TimeUnit.NANOSECONDS) / 1000.0)

1 个解决方案

#1


4  

you can use setScale

你可以使用setScale

BigDecimal(19.1234).setScale(2, BigDecimal.RoundingMode.DOWN)
=> res: scala.math.BigDecimal = 19.12

#1


4  

you can use setScale

你可以使用setScale

BigDecimal(19.1234).setScale(2, BigDecimal.RoundingMode.DOWN)
=> res: scala.math.BigDecimal = 19.12