-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Razor Components (Blazor 0.8) - "double/float/decimal" error parse #7655
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
Comments
Probably you have a system with decimal separator set to comma. Parse without culture uses current culture. They should use InvariantCulture. It looks that similar bug was introduced in new forms components: |
@javiercn can you please try to reproduce this? Thanks! |
After doing some investigations here are my conclusions.
I'm by no means an internationalization expert. @rynowak do you have spicy thoughts on this topic? As a plan of record, we should start by making things parse data using the invariant culture, and when we can see other options. |
Not sure how doable is to write an E2E test for this. |
@cores-system What's the locale in your machine? |
@javiercn, ru_RU |
@cores-system Thanks. Here is the confirmation:
|
Looking forward, he main thing that can cause issues here is the fact that there might be normalized values and non normalized values at play depending on what you use type="number" or type="text" for example. There might even be cases where choosing a different culture doesn't error out, but produces the wrong value. It might be ok to say here that if you choose to bind to double it's invariant culture every single time, and that if you have type="text" you need to do the parsing yourself to a number or accept invariant culture as the culture. That said, we should provide a way to flow the browser culture to the application. |
I think that we should always use invariant culture in double/float/decimal binding. It should be documented that this will work correctly only with <!DOCTYPE html>
<html>
<body>
<div>
pl-pl <input lang="pl-pl" id="input-pl" type="number" step="0.01">
<br>
en-us <input lang="en-us" id="input-us" type="number" step="0.01">
<br>
<button onclick="setValues()">Set Values</button>
<button onclick="getValues()">Get Values</button>
</div>
<div>
pl-pl:<span id="value-pl"></span>
<br>
en-us:<span id="value-us"></span>
</div>
<script>
function getValues(){
document.getElementById("value-pl").innerHTML = document.getElementById("input-pl").value;
document.getElementById("value-us").innerHTML = document.getElementById("input-us").value;
}
function setValues(){
document.getElementById("input-pl").value = 1234.12;
document.getElementById("input-us").value = 1234.12;
}
</script>
</body>
</html> In Firefox it works as expected: first input field displays numbers with coma decimal separator and second input field displays dot. Polish Chrome displays comma in both input fields which is in my opinion wrong. Fortunately I agree with @javiercn that if I want to use |
Closing this issue as this work will be covered as part of the referenced |
Describe the bug
If i use
type="number"
parameter I cannot usedouble / float / decimal
inbind
.To Reproduce
When I enter
4.1
or4,1
into input, I get an error message.Additional context
https://github.com/aspnet/AspNetCore/blob/master/src/Components/Components/src/BindMethods.cs#L155
The text was updated successfully, but these errors were encountered: