MCPcopy
hub / github.com/autoNumeric/autoNumeric / _calculateDecimalPlacesOnInit

Method _calculateDecimalPlacesOnInit

src/AutoNumeric.js:8146–8180  ·  view source on GitHub ↗

* Calculate the number de decimal places to be used by the AutoNumeric object, for each of its state, and for its formatted and raw value. * By default, the `rawValue` precision is the same as the formatted value one. * * This method is called during the AutoNumeric object initializat

(settings)

Source from the content-addressed store, hash-verified

8144 * @private
8145 */
8146 static _calculateDecimalPlacesOnInit(settings) {
8147 // Check the `decimalPlaces*` options and output any warnings as needed, before modifying those options
8148 this._validateDecimalPlacesRawValue(settings);
8149
8150 // Initialization phase
8151 //XXX This assumes at this stage, `settings.decimalPlaces` as been set from the default options
8152
8153 // Overwrite the `decimalPlaces*` values if the `decimalPlaces*` options are not set in the `settings`
8154 // Sets `decimalPlacesShownOnBlur` (previously known as `scaleDecimalPlaces`)
8155 if (settings.decimalPlacesShownOnFocus === AutoNumeric.options.decimalPlacesShownOnFocus.useDefault) {
8156 settings.decimalPlacesShownOnFocus = settings.decimalPlaces;
8157 }
8158
8159 if (settings.decimalPlacesShownOnBlur === AutoNumeric.options.decimalPlacesShownOnBlur.useDefault) {
8160 settings.decimalPlacesShownOnBlur = settings.decimalPlaces;
8161 }
8162
8163 if (settings.decimalPlacesRawValue === AutoNumeric.options.decimalPlacesRawValue.useDefault) {
8164 settings.decimalPlacesRawValue = settings.decimalPlaces;
8165 }
8166
8167 // Add the additional decimal places to the raw value
8168 let additionalDecimalPlacesRawValue = 0;
8169 if (settings.rawValueDivisor && settings.rawValueDivisor !== AutoNumeric.options.rawValueDivisor.none) {
8170 additionalDecimalPlacesRawValue = String(settings.rawValueDivisor).length - 1; // i.e. Dividing by '100' adds 2 decimal places to the needed precision
8171 if (additionalDecimalPlacesRawValue < 0) {
8172 additionalDecimalPlacesRawValue = 0;
8173 }
8174 }
8175
8176 settings.decimalPlacesRawValue = Math.max(
8177 Math.max(settings.decimalPlacesShownOnBlur, settings.decimalPlacesShownOnFocus) + additionalDecimalPlacesRawValue,
8178 Number(settings.originalDecimalPlacesRawValue) + additionalDecimalPlacesRawValue,
8179 );
8180 }
8181
8182 /**
8183 * Recalculate the number de decimal places to be used by the AutoNumeric object, for each of its state, and for its formatted and raw value.

Callers 3

formatMethod · 0.95
unformatMethod · 0.95
_setSettingsMethod · 0.80

Calls 1

Tested by

no test coverage detected