* 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 cha
(value, settings)
| 8599 | * @returns {string|NaN} |
| 8600 | */ |
| 8601 | static _toNumericValue(value, settings) { |
| 8602 | //XXX Note; this function is static since we need to pass a `settings` object when calling the static `AutoNumeric.format()` method |
| 8603 | let result; |
| 8604 | if (AutoNumericHelper.isNumber(Number(value))) { // if (settings.decimalCharacter === '.' && AutoNumericHelper.isNumber(Number(value))) { |
| 8605 | // The value has either already been stripped, or a 'real' javascript number is passed as a parameter |
| 8606 | if (!AutoNumericHelper.isNumberStrict(value)) { |
| 8607 | value = String(value).trim(); // cf. issue #721 |
| 8608 | } |
| 8609 | result = AutoNumericHelper.scientificToDecimal(value); |
| 8610 | } else { |
| 8611 | // Else if it's a string that `Number()` cannot typecast, then we try to convert the localized numeric string to a numeric one |
| 8612 | // Convert the value to a numeric string, stripping unnecessary characters in the process |
| 8613 | result = this._convertToNumericString(value.toString(), settings); |
| 8614 | |
| 8615 | // If the result is still not a numeric string, then we throw a warning |
| 8616 | if (!AutoNumericHelper.isNumber(Number(result))) { |
| 8617 | AutoNumericHelper.warning(`The given value "${value}" cannot be converted to a numeric one and therefore cannot be used appropriately.`, settings.showWarnings); |
| 8618 | result = NaN; |
| 8619 | } |
| 8620 | } |
| 8621 | |
| 8622 | return result; |
| 8623 | } |
| 8624 | |
| 8625 | /** |
| 8626 | * Return the pasted text that will be used, by stripping most non-numeric characters |
no test coverage detected