MCPcopy
hub / github.com/autoNumeric/autoNumeric / _truncateDecimalPlaces

Method _truncateDecimalPlaces

src/AutoNumeric.js:6013–6031  ·  view source on GitHub ↗

* Truncates the decimal part of a number to the given number of decimal places `decimalPlacesToRoundTo`. * * @param {string} value * @param {object} settings * @param {boolean} isPaste * @param {int} decimalPlacesToRoundTo * @returns {*}

(value, settings, isPaste, decimalPlacesToRoundTo)

Source from the content-addressed store, hash-verified

6011 * @returns {*}
6012 */
6013 static _truncateDecimalPlaces(value, settings, isPaste, decimalPlacesToRoundTo) {
6014 if (isPaste) {
6015 value = this._roundFormattedValueShownOnFocus(value, settings);
6016 }
6017
6018 const [integerPart, decimalPart] = value.split(settings.decimalCharacter);
6019
6020 // Truncate the decimal part to the satisfying length since we would round it anyway
6021 if (decimalPart && decimalPart.length > decimalPlacesToRoundTo) {
6022 if (decimalPlacesToRoundTo > 0) {
6023 const modifiedDecimalPart = decimalPart.substring(0, decimalPlacesToRoundTo);
6024 value = `${integerPart}${settings.decimalCharacter}${modifiedDecimalPart}`;
6025 } else {
6026 value = integerPart;
6027 }
6028 }
6029
6030 return value;
6031 }
6032
6033 /**
6034 * Check if the given value is within the `minimumValue` and `maximumValue` range, while using the override options set with `overrideMinMaxLimits`.

Callers 1

_setValuePartsMethod · 0.80

Tested by

no test coverage detected