* Converts the ISO numeric string to the locale decimal and minus sign placement. * See the "outputFormat" option definition for more details. * Note: If the `outputFormat` is set to a number, the custom `negativeSignCharacter` is ignored. * * @param {string|null} value The unfor
(value, locale, settings)
| 5208 | * @returns {*} |
| 5209 | */ |
| 5210 | static _toLocale(value, locale, settings) { |
| 5211 | if (AutoNumericHelper.isNull(locale) || locale === AutoNumeric.options.outputFormat.string) { |
| 5212 | return value; |
| 5213 | } |
| 5214 | |
| 5215 | let result; |
| 5216 | switch (locale) { |
| 5217 | case AutoNumeric.options.outputFormat.number: |
| 5218 | result = Number(value); |
| 5219 | break; |
| 5220 | case AutoNumeric.options.outputFormat.dotNegative: |
| 5221 | result = AutoNumericHelper.isNegative(value) ? value.replace('-', '') + '-' : value; |
| 5222 | break; |
| 5223 | case AutoNumeric.options.outputFormat.comma: |
| 5224 | case AutoNumeric.options.outputFormat.negativeComma: |
| 5225 | result = value.replace('.', ','); |
| 5226 | break; |
| 5227 | case AutoNumeric.options.outputFormat.commaNegative: |
| 5228 | result = value.replace('.', ','); |
| 5229 | result = AutoNumericHelper.isNegative(result) ? result.replace('-', '') + '-' : result; |
| 5230 | break; |
| 5231 | // The default case |
| 5232 | case AutoNumeric.options.outputFormat.dot: |
| 5233 | case AutoNumeric.options.outputFormat.negativeDot: |
| 5234 | result = value; |
| 5235 | break; |
| 5236 | default : |
| 5237 | AutoNumericHelper.throwError(`The given outputFormat [${locale}] option is not recognized.`); |
| 5238 | } |
| 5239 | |
| 5240 | if (locale !== AutoNumeric.options.outputFormat.number && settings.negativeSignCharacter !== '-') { |
| 5241 | // Modify the default minus sign with the custom one, if any |
| 5242 | result = result.replace('-', settings.negativeSignCharacter); |
| 5243 | } |
| 5244 | |
| 5245 | return result; |
| 5246 | } |
| 5247 | |
| 5248 | /** |
| 5249 | * Modify the negative sign and the decimal character of the given string value to a hyphen (-) and a dot (.) in order to make that value 'typecastable' to a real number. |
no test coverage detected