# Float types with inputs?

**URL:** <https://discourse.elm-lang.org/t/float-types-with-inputs/6316>\
**Category:** Learn\
**Created:** [September 29, 2020, 1:04am UTC](https://discourse.elm-lang.org/t/float-types-with-inputs/6316 "2020-09-29T01:04:29Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![cmanallen](https://avatars.discourse-cdn.com/v4/letter/c/67e7ee/32.png) [@cmanallen](https://discourse.elm-lang.org/u/cmanallen)\
**Post date:** [September 29, 2020, 1:04am UTC](https://discourse.elm-lang.org/t/float-types-with-inputs/6316/1 "2020-09-29T01:04:29Z")

</div>

Hi,

I’m trying to make a simple money app with Elm 1.19.1. When a user enters a value in the input I’m setting that value on the model. I’m also re-painting the input with the value that was just entered. Meaning if the user provided something invalid then it will default to something other than what they entered.

This works great for integers. But for floats something like “32.” instantly breaks because the period is removed by the update function (`String.toFloat |> Maybe.withDefault model.value`). I’m wondering what is the best way to manage this?

```auto
type Model alias = { value : Float }

type Msg = SetValue String

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        SetValue val ->
            ( { model | value = val |> String.toFloat |> Maybe.withDefault model.value }, Cmd.none )

view : Model -> Html Msg
view model =
    input [onInput SetValue, value model.value] []

```

I don’t want to store it as a string on the model because I feel like I lose that free validation. But I don’t know. Whats the best practice here?

---

_[View the full topic](https://discourse.elm-lang.org/t/float-types-with-inputs/6316)._
