This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

Exts.Float

Extensions to the core Float library.

roundTo : Int -> Float -> Float

Round a Float to a given number of decimal places.

module Exts.Float exposing (roundTo)

{-| Extensions to the core `Float` library.

@docs roundTo

-}


{-| Round a `Float` to a given number of decimal places.
-}
roundTo : Int -> Float -> Float
roundTo places value =
    let
        factor =
            toFloat (10 ^ places)
    in
    ((value * factor)
        |> round
        |> toFloat
    )
        / factor