--- title: v-model.number Uses parseFloat Not valueAsNumber impact: MEDIUM impactDescription: .number modifier returns empty string for empty input and uses parseFloat, not native valueAsNumber type: capability tags: [vue3, v-model, forms, input, number, type-coercion, modifiers] --- # v-model.number Uses parseFloat Not valueAsNumber **Impact: MEDIUM** - The `.number` modifier doesn't behave like the native `valueAsNumber` property. It returns an empty string (not NaN) for empty inputs, and uses `parseFloat()` which has different parsing rules. This can cause unexpected type issues in calculations and validations. Understanding these differences is crucial when working with numeric forms, especially for calculations, min/max validation, or when interfacing with APIs that expect strict number types. ## Task Checklist - [ ] Expect empty string (not 0 or NaN) when input is cleared with `.number` modifier - [ ] Handle the empty string case in your validation and calculations - [ ] Remember `.number` uses parseFloat - "123abc" becomes 123, not NaN - [ ] For strict numeric parsing, add custom validation **Key Differences:** | Scenario | `.number` modifier | Native `valueAsNumber` | |----------|-------------------|----------------------| | Empty input | `''` (empty string) | `NaN` | | `"123"` | `123` | `123` | | `"123.45"` | `123.45` | `123.45` | | `"123abc"` | `123` | `NaN` | | `"abc"` | `'abc'` (original string) | `NaN` | **Problem - Unexpected types:** ```html ``` **Solution - Handle empty string explicitly:** ```html ``` **Solution - Custom input handling for strict parsing:** ```html ``` ## Reference - [Vue.js Form Input Bindings - .number](https://vuejs.org/guide/essentials/forms.html#number)