You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
German numbers with on grouping/thousands dot will be handled on page-load (or ajax-replace) as english numbers
so 1.000 gets 1.0 (one thousand is converted to one)
900.000 gets 900
(only if there are no decimal digits)
Expected behavior
German numbers between 1.000 und 999.999 should not be changed
Steps to reproduce the problem
Save and open following HTML:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/autonumeric/4.6.0/autoNumeric.js"></script>
<script>
window.addEventListener("load", (event) => {
new AutoNumeric("input", {
currencySymbol: "",
decimalCharacter: ",",
digitGroupSeparator: ".",
decimalPlaces: 2
});
});
</script>
</head>
<body>
<input type="text" value="12.345" />value=12.345 - the german 12.345,00 but without decimal places<br />
<input type="text" value="1.234.567"/>value=1.234.567 - the german 1.234.567,00 but without decimal places<br />
</body>
</html>
<Also, when creating an extract of your problem, you are likely to find the cause of it, and fix it yourself, 🎉 ;)>
The Problem is in autoNumeric.js (4.6.0) line 10389 in the "_toNumericValue" function.
The first IF for "normal" (english-styled) numbers also miss-matches for german integers between 1.000 and 999.999.
My fix was to check the actual decimalCharacter by changing the original
if (AutoNumericHelper__WEBPACK_IMPORTED_MODULE_0_["default"].isNumber(Number(value))) {
to
if (settings.decimalCharacter == this.getDefaultConfig().decimalCharacter && AutoNumericHelper__WEBPACK_IMPORTED_MODULE_0_["default"].isNumber(Number(value))) {
(found no static access to AutoNumeric__WEBPACK_IMPORTED_MODULE_0_["default"].options.decimalCharacter.dot)
Another question:
Is there a "hidden" (i haven't found it) function to add the decimal digits directly while typing, not afterwards on blur?
So when i type "1" in an empty field it gets automatically to "1.00" (in english-format), with cursor staying after "1"?
The text was updated successfully, but these errors were encountered:
Here is the link to the related live code example to try to reproduce the aforementioned problem.
AutoNumeric does try to parse any javascript-formatted Number passed as the 'default' value.
AutoNumeric does not try to unformat the default attribute value, so using 12.345, it's correctly interpreted as the decimal number 12.345.
As you can see in the code, the docs for _toNumericValue() states:
Convert the `value` parameter that can either be :
- a real number,
- a number represented in the scientific notation (i.e. -123.4567e-6)
- a string representing a real number, or
- a string representing a localized number (with specific group separators and decimal character),
...to a string representing a real 'javascript' number (i.e. '1234' or '1234.567').
This function returns `NaN` if such conversion fails.
All in all, the default attribute value should always be used with a Javascript Number, not with a formatted one.
Current behavior
German numbers with on grouping/thousands dot will be handled on page-load (or ajax-replace) as english numbers
so 1.000 gets 1.0 (one thousand is converted to one)
900.000 gets 900
(only if there are no decimal digits)
Expected behavior
German numbers between 1.000 und 999.999 should not be changed
Steps to reproduce the problem
Save and open following HTML:
https://pastebin.com/BdgYVacY
Fix
<Also, when creating an extract of your problem, you are likely to find the cause of it, and fix it yourself, 🎉 ;)>
The Problem is in autoNumeric.js (4.6.0) line 10389 in the "_toNumericValue" function.
The first IF for "normal" (english-styled) numbers also miss-matches for german integers between 1.000 and 999.999.
My fix was to check the actual decimalCharacter by changing the original
if (AutoNumericHelper__WEBPACK_IMPORTED_MODULE_0_["default"].isNumber(Number(value))) {
to
if (settings.decimalCharacter == this.getDefaultConfig().decimalCharacter && AutoNumericHelper__WEBPACK_IMPORTED_MODULE_0_["default"].isNumber(Number(value))) {
(found no static access to AutoNumeric__WEBPACK_IMPORTED_MODULE_0_["default"].options.decimalCharacter.dot)
Another question:
Is there a "hidden" (i haven't found it) function to add the decimal digits directly while typing, not afterwards on blur?
So when i type "1" in an empty field it gets automatically to "1.00" (in english-format), with cursor staying after "1"?
The text was updated successfully, but these errors were encountered: