Number -0 cannot be correctly rendered in input :value



Reproduction link

Steps to reproduce

  1. Open reproduction link
  2. Compare display value from input tag rendered by Vue and plain input html tag

What is expected?

Input dom should correctly render value -0

What is actually happening?

It renders as 0

In javascript, Number -0 is legitimate value, this can be verified by checking Number(-0) === -0. Therefore, when input :value is number -0, input tag should correctly display it, just as a plain input html tag does.

2 thoughts on “Number -0 cannot be correctly rendered in input :value

  1. Note an input does the same if you set its value through JS: inputEl.value = -0 -> 0 in the String.

    As a workaround, you can use a string version with v-model.

    In practice, except for Mathematical applications, differentiating between -0 and +0. But even then, one would use something to correctly handle large numbers.

    What is your use case?

  2. As this would break existing cases with v-model.number and -0 and would never replace the need of a custom handled input with a string value, I don’t think this is worth pursuing in core, but rather in a plugin to handle all the possible edge cases for numbers. In Vue 3, this could be handled with a custom modifier

Comments are closed.