Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. module Main exposing (..)
  2.  
  3. import Html exposing (beginnerProgram, div, button, text)
  4. import Html.Events exposing (onInput)
  5. import Html.Attributes as HA
  6. import String
  7.  
  8.  
  9. main =
  10. beginnerProgram { model = 0.0, view = view, update = update }
  11.  
  12.  
  13. -- This assumes using 0.0 formatting. Other locales might use a , or other symbol.
  14. toFixed : Float -> String
  15. toFixed n =
  16. let
  17. parts =
  18. String.split "." (toString n)
  19.  
  20. parts_ =
  21. if List.length parts == 1 then
  22. parts ++ [ "0" ]
  23. else
  24. parts
  25. in
  26. String.join "." parts_
  27.  
  28.  
  29. view model =
  30. div []
  31. [ Html.input [ HA.type_ "text", HA.value (toFixed model), onInput Change ] []
  32. ]
  33.  
  34.  
  35. type Msg
  36. = Change String
  37.  
  38.  
  39. update msg model =
  40. case msg of
  41. Change n ->
  42. Result.withDefault model (String.toFloat n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement