* Return a number as a numeric string that can be typecast to a Number that Javascript will understand. * * This function returns the given string by stripping: * - the currency sign (currencySymbol), * - the grouping separators (digitalGroupSpacing), * - the suffix text (su
(s, settings)
| 5135 | * @returns {string|void|*} |
| 5136 | */ |
| 5137 | static _convertToNumericString(s, settings) { |
| 5138 | // Remove the custom brackets |
| 5139 | s = this._removeBrackets(s, settings, false); |
| 5140 | s = this._normalizeCurrencySuffixAndNegativeSignCharacters(s, settings); |
| 5141 | |
| 5142 | // Remove the grouping separators (thousands separators usually) |
| 5143 | s = s.replace(new RegExp(`[${settings.digitGroupSeparator}]`, 'g'), ''); |
| 5144 | |
| 5145 | // Replace the decimal character by a dot |
| 5146 | if (settings.decimalCharacter !== '.') { |
| 5147 | s = s.replace(settings.decimalCharacter, '.'); |
| 5148 | } |
| 5149 | |
| 5150 | // Move the trailing negative sign, if any, to the usual leftmost position |
| 5151 | if (AutoNumericHelper.isNegative(s) && s.lastIndexOf('-') === s.length - 1) { |
| 5152 | s = s.replace('-', ''); |
| 5153 | s = `-${s}`; |
| 5154 | } |
| 5155 | |
| 5156 | // Replace the custom positive sign |
| 5157 | if (settings.showPositiveSign) { |
| 5158 | s = s.replace(settings.positiveSignCharacter, ''); |
| 5159 | } |
| 5160 | |
| 5161 | // Convert arabic numbers to latin ones, if any |
| 5162 | const convertToNumber = settings.leadingZero !== AutoNumeric.options.leadingZero.keep; |
| 5163 | const temp = AutoNumericHelper.arabicToLatinNumbers(s, convertToNumber, false, false); |
| 5164 | if (!isNaN(temp)) { |
| 5165 | s = temp.toString(); |
| 5166 | } |
| 5167 | |
| 5168 | return s; |
| 5169 | } |
| 5170 | |
| 5171 | /** |
| 5172 | * Removes the currency symbol and the suffix text from the given string, and replace the custom negative sign with a hyphen. |
no test coverage detected