I would like to change the precision of double value.
For example:
I need to get 3.14 from 3.141592653589793
I expect function like:
scale :: Int -> Double -> Double
> scale 2 3.141592653589793
3.14
> scale 3 3.141592653589793
3.141
Also, I would like to be able to choose the rounding strategy.
round :: ROUND -> Int -> Double -> Double
> round ROUNDUP 5 3.141592653589793
3.1416
- How can I do it?
- How can I apply the rounding strategy for it?
P.S.:
Expected behavior in Java should setScale of BigDecimal: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html