* Removes any zeros in excess in the front and back of the given `value`, according to the `settings`. * This also manages the cases where the decimal point is on the far left or far right of the `value`. * * @param {string} value * @returns {string|null}
(value)
| 6216 | * @returns {string|null} |
| 6217 | */ |
| 6218 | _trimLeadingAndTrailingZeros(value) { |
| 6219 | // Return the empty string is the value is already empty. This prevents converting that value to '0'. |
| 6220 | if (value === '' || value === null) { |
| 6221 | return value; |
| 6222 | } |
| 6223 | |
| 6224 | if (this.settings.leadingZero !== AutoNumeric.options.leadingZero.keep) { |
| 6225 | if (Number(value) === 0) { |
| 6226 | // Return '0' if the value is zero |
| 6227 | return '0'; |
| 6228 | } |
| 6229 | |
| 6230 | // Trim the leading zeros, while leaving one zero to the left of the decimal point if needed |
| 6231 | value = value.replace(/^(-)?0+(?=\d)/g,'$1'); |
| 6232 | } |
| 6233 | |
| 6234 | //TODO remove this from that function and use `trimPaddedZerosFromDecimalPlaces()` instead |
| 6235 | // Trim the trailing zeros after the last decimal place not being a zero (i.e. 1.2300 -> 1.23) |
| 6236 | if (AutoNumericHelper.contains(value, '.')) { |
| 6237 | value = value.replace(/(\.[0-9]*?)0+$/, '$1'); |
| 6238 | } |
| 6239 | |
| 6240 | // Remove any trailing decimal point |
| 6241 | value = value.replace(/\.$/, ''); |
| 6242 | |
| 6243 | return value; |
| 6244 | } |
| 6245 | |
| 6246 | /** |
| 6247 | * Generate the name for the persistent stored data variable |
no test coverage detected