Correction 

toString (toFloat "5.") == "5"    -i.e. the `.` gets stripped off so you 
can never actually add decimal values



On Saturday, 21 January 2017 16:08:04 UTC+1, Simon wrote:
>
> I think it is not uncommon to collect dates and float values from users.
>
> update ...
>     NewValue v -> 
>         { model | floatvalue = String.toFloat v |> Result.withDefault 0.0 }
>
> floatInput : Float -> Html Msg 
> floatInput v =
>     input 
>         [ onInput NewValue 
>         , value (toString v) 
>         ] []
>
> The problem with the above is that the moment you type the . toFloat 
> fails and you get a 0 in your model. One way around it could be to delay 
> processing of the value by using onBlur (below), but I was wondering how 
> others handled this.
>
> floatInput_ : Float -> Html Msg 
> floatInput_ v =
>     input 
>         [ onBlur NewValue 
>         , value (toString v) 
>         ] []
>
> ​
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to