React-number-format: Can't use decimal separator at the end of value

Created on 24 Oct 2017  路  6Comments  路  Source: s-yadav/react-number-format

When typing a number usually you go from left to right which means you first type the thousands then a decimal separator ( . or , ) and then decimals, right now it isn't letting me use decimal separator if i don't have a number before it
example:
123 (i can add a separator between 2 and 3 but i can't add one after 3)

this is the config of my NumberFormat (currently using version: 3.0.0-beta2)
value={value}
onValueChange={values => onValueChange(values.floatValue)}
thousandSeparator={"."}
decimalSeparator={","}
decimalScale={8}
/>

Most helpful comment

Fixed it on 3.3.1

All 6 comments

Float value cannot have a number ending with decimal without post decimal numbers. Use formattedValue / value instead.

<NumberFormat
value={value}
onValueChange={values => onValueChange(values.formattedValue)}
thousandSeparator={"."}
decimalSeparator={","}
decimalScale={8}
/>

Note: If you using values.value do provide isNumericString prop to true

ty, worked!

Well, I have digit the comma and I don't catch floatValue, so... How I fixed this?
References: https://github.com/s-yadav/react-number-format/issues/114

@s-yadav Only problem with passing isNumericString={true} is that an empty value (value = '') adds a zero (0) to the input.

What is the best way to keep the input empty like an empty string? Thanks! Would love to contribute to this if it needs it.

Fixed it on 3.3.1

Awesome! Thank you!

@s-yadav Another question for you: Is there a way to start an input value with a decimal? For example .66 instead of 0.66? Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erasmo-marin picture erasmo-marin  路  3Comments

TkDodo picture TkDodo  路  5Comments

sezarthiago picture sezarthiago  路  7Comments

cescoferraro picture cescoferraro  路  6Comments

rioarray picture rioarray  路  6Comments