Romano
Romano

Reputation: 117

Haskell from float to Double

I've been trying to learn haskell for a couple days but I can't see to figure out how to create an answer/output that is a float, to a double

module SpaceAge ( Planet(..), ageOn) where
-- calculate seconds to an age on different planets
data Planet = Earth
            | Jupiter
            | Mars
            | Mercury
            | Neptune
            | Saturn
            | Uranus
            | Venus

-- one year has 31557600 seconds
orbitalPeriodInSeconds :: Planet -> Float
orbitalPeriodInSeconds planet = 31557600 * multiplier where
    multiplier = case planet of
        Earth   -> 1.0
        Jupiter -> 11.862615
        Mars    -> 1.8808158
        Mercury -> 0.2408467
        Neptune -> 164.79132
        Saturn  -> 29.447498
        Uranus  -> 84.016846
        Venus   -> 0.61519726

-- user input example: ageOn Venus 9303000
ageOn :: Planet -> Float -> Float
ageOn planet seconds = seconds / orbitalPeriodInSeconds planet

The answer/output will be a float but I need to get a double. Example

*SpaceAge> ageOn Mercury 2134835688
280.87936

But I need 280.88
Offcourse the compiler will raise errors if I change Float to Double because it expect a Float.

Upvotes: 1

Views: 649

Answers (1)

If the need is to display the result you can use showFFloat from Numeric

showFFloat (Just 2) 280.87936 ""

Upvotes: 3

Related Questions