Is there a simple function to round a Double
or Float
to a specified number of digits? I've searched here and on Hoogle (for (Fractional a) => Int -> a -> a
), but haven't found anything.
相关问题
- Understanding do notation for simple Reader monad:
- Global overloading of == and != for floating-point
- Making Custom Instances of PersistBackend
- Haskell: What is the differrence between `Num [a]
- applying a list to an entered function to check fo
相关文章
- Is it possible to write pattern-matched functions
- Haskell underscore vs. explicit variable
- Top-level expression evaluation at compile time
- Stuck in the State Monad
- foldr vs foldr1 usage in Haskell
- List of checkboxes with digestive-functors
- How does this list comprehension over the inits of
- Replacing => in place of -> in function type signa
It depends on what you are going to do with the rounded number.
If you want to use it in calculations, you should use
Data.Decimal
fromDecimal
library.If you want just to format the number nicely, you should use
Text.Printf
from the standard library (base
package).Not sure whether any standard function exists, but you can do it this way: