Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main exposing (..)
- import Html exposing (beginnerProgram, div, button, text)
- import Html.Events exposing (onInput)
- import Html.Attributes as HA
- import String
- main =
- beginnerProgram { model = 0.0, view = view, update = update }
- -- This assumes using 0.0 formatting. Other locales might use a , or other symbol.
- toFixed : Float -> String
- toFixed n =
- let
- parts =
- String.split "." (toString n)
- parts_ =
- if List.length parts == 1 then
- parts ++ [ "0" ]
- else
- parts
- in
- String.join "." parts_
- view model =
- div []
- [ Html.input [ HA.type_ "text", HA.value (toFixed model), onInput Change ] []
- ]
- type Msg
- = Change String
- update msg model =
- case msg of
- Change n ->
- Result.withDefault model (String.toFloat n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement