MCPcopy
hub / github.com/autoNumeric/autoNumeric / _prepareValueForRounding

Method _prepareValueForRounding

src/AutoNumeric.js:5951–5978  ·  view source on GitHub ↗

* Modify the given `value` in order to make it usable for the rest of the rounding function. * This convert the `value` to a positive one, trim any leading zeros and make sure it does not start with a leading dot. * * @param {string} value The unformatted value * @param {object}

(value, settings)

Source from the content-addressed store, hash-verified

5949 * @private
5950 */
5951 static _prepareValueForRounding(value, settings) {
5952 // Checks if `inputValue` is a negative value
5953 let negativeSign = '';
5954 if (AutoNumericHelper.isNegativeStrict(value, '-')) { // The value being unformatted, we check for the minus sign
5955 negativeSign = '-';
5956
5957 // Removes the negative sign that will be added back later if required
5958 value = value.replace('-', '');
5959 }
5960
5961 // Append a zero if the first character is not a digit (then it is likely a dot)
5962 if (!value.match(/^\d/)) {
5963 value = `0${value}`;
5964 }
5965
5966 // Determines if the value is equal to zero. If it is, remove the negative sign
5967 if (Number(value) === 0) {
5968 negativeSign = '';
5969 }
5970
5971 // Trims leading zero's as needed
5972 if ((Number(value) > 0 && settings.leadingZero !== AutoNumeric.options.leadingZero.keep) ||
5973 (value.length > 0 && settings.leadingZero === AutoNumeric.options.leadingZero.allow)) {
5974 value = value.replace(/^0*(\d)/, '$1');
5975 }
5976
5977 return [negativeSign, value];
5978 }
5979
5980 /**
5981 * Return `true` if a round up should be done given the last digit, the settings and other information about the value.

Callers 1

_roundValueMethod · 0.80

Calls 1

isNegativeStrictMethod · 0.80

Tested by

no test coverage detected