-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow decimals to end in "zero" #433
Comments
+1 |
This is due to https://github.com/mozilla-services/react-jsonschema-form/blob/master/src/utils.js#L210-L215. It seems to me that there are two use cases here -- one for numeric values for which a trailing zero is semantically meaningless (and so we should allow it), and one for fixed-point numbers for which a trailing zero is meaningful, like for dollars-and-cents amounts. NumberField corresponds to the JSON type "number", which means that it matches the first use case. I'd like to reserve the ability to use fields for fixed-width decimal formats, but I don't see how we could deserialize its data as anything except |
The problem is trailing zeros are not preserved when serializing to JSON: > JSON.parse("3.10")
3.1
> JSON.parse(JSON.stringify(3.10))
3.1
> 3.10
3.1 This library relies on JSON schema, hence on the JSON spec wrt value validation. My take is if you want trailing zeros in your numbers, you may actually want strings instead. I know this is not ideal, but I don't have any other idea how to preserve trailing zeros in numbers when the language & spec themselves don't allow it. |
Also another solution if you always want two digits after the comma would be to make to multiply the value by 100 (round it to its integer value) and then devide it by 100 and it will put it back. |
I've hit this issue recently as well. I don't need the trailing 0 to be preserved but it would be good if what is clearly a numeric value doesn't fail validation with the error "should be number" |
Has anyone had any updates on this, in our use case we need to maintain the trailing 0s. But even if that wasnt supported I would expect it to strip them and move on. But like mentioned above
that seems like a bug. |
@travisdahl I believe this was solved in #1183 and is included in the latest release. |
@epicfaace my bad, we upgraded and saw the fix. It still drops the zeros but besides that it seems to be working |
Prerequisites
Steps to Reproduce
Expected behavior
Don't throw type error for 3.10
Actual behavior
Type error thrown for 3.10
The text was updated successfully, but these errors were encountered: