Fix parsing in locales that use a different decimal separator. #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a correction to #58.
Number parsing in
MathExpression.parseMathExpression()
will now try to use aNumberFormat
given by theTextFieldWidget
using it; or the system defaultNumberFormat
if none has been provided (or if called from outside aTextFieldWidget
).This means that numbers are now correctly parsed in locales that use a different thousands and decimal separators than
,
and.
. Hopefully this should fix tests failing for @Dream-Master .However current code still uses a mix of locale-aware formatting, and
String.valueOf()
. Also, since the raw text of the widget is exposed to the user, there is no way to guarantee that whoever is using the widget follows locale settings correctly.Specifically for integer numbers, right now, this does not matter; as
BaseTextFieldWidget
hides thousands separators; and so most common number formats will appear identical. But if anybody wants a widget that can show non-integer decimal numbers, or to show thousands separators (the latter of which I would like to do), this could cause problems.(And just for clarity, this problem is not caused by either this PR or the previous one; it was present in the code before too. It was only not apparent because people didn't try to input decimal numbers into the text field.)
I can see at least two possible solutions:
NumericWidget
, which would only expose the numeric value to the user, and manage all input/parsing/display on its own. Then switch over any code that previously used aTextWidget
to input numbers to the new numeric widget.