DoubleValidator strange behavior
-
I'm using QML and I need textfields that only accept doubles. I used DoubleValidator for this. However, when I enter, for example a 0.2 in the textfield and hit tab, it will change the value to 2. The same holds for any number formatted as "0.00...0x". When I write any other number after the x, though, it will work correctly. I have no idea why this is and why anyone would want this. What am I doing wrong?
-
I'm using QML and I need textfields that only accept doubles. I used DoubleValidator for this. However, when I enter, for example a 0.2 in the textfield and hit tab, it will change the value to 2. The same holds for any number formatted as "0.00...0x". When I write any other number after the x, though, it will work correctly. I have no idea why this is and why anyone would want this. What am I doing wrong?
@f-ij Which locale are you using? In some country like France the period is just a separator for thousands and it's the comma that is used as a decimals marker.
You can force a locale on your DoubleValidator if you don't want to use the system one:
locale: "en"
-
@f-ij Which locale are you using? In some country like France the period is just a separator for thousands and it's the comma that is used as a decimals marker.
You can force a locale on your DoubleValidator if you don't want to use the system one:
locale: "en"
@GrecKo said in DoubleValidator strange behavior:
locale: "en"
Thanks so much, this was indeed the problem! I suspected something like this at some point, and tried using a comma as a separator, but this wasn't accepted due to me using the parseFloat function somewhere in my code, which I mistakenly took as validation that commas weren't the right separator in the DoubleValidator.