Skip to content

Commit 762f7ae

Browse files
authored
NumberBox: it should be possible to use percent format with more than 7 fractional digits (T1277123)
1 parent 3ee6e48 commit 762f7ae

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/devextreme/js/__internal/ui/number_box/m_number_box.mask.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,21 @@ const NumberBoxMask = NumberBoxBase.inherit({
452452
const value = parsedValue === null ? this._parsedValue : parsedValue;
453453
parsedValue = maxPrecision ? this._truncateToPrecision(value, maxPrecision) : parsedValue;
454454

455-
return !format.parser && this._isPercentFormat() ? adjustPercentValue(parsedValue, maxPrecision) : parsedValue;
455+
if (!format.parser && this._isPercentFormat()) {
456+
const interval = this._getIntervalFromPrecision(maxPrecision);
457+
458+
return adjustPercentValue(parsedValue, interval);
459+
}
460+
461+
return parsedValue;
462+
},
463+
464+
_getIntervalFromPrecision(precision: number) {
465+
if (precision < 1) {
466+
return 1;
467+
}
468+
469+
return 10 ** -precision;
456470
},
457471

458472
_getParsedValue(text, format) {

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/numberBoxParts/mask.tests.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,10 @@ QUnit.module('format: percent format', moduleConfig, () => {
13691369
[
13701370
{ text: '14.55', value: 0.1455 },
13711371
{ text: '20.2', value: 0.202 },
1372-
{ text: '1.0154', value: 0.010154, format: '#0.####%' }
1372+
{ text: '1.0154', value: 0.010154, format: '#0.####%' },
1373+
{ text: '0.123456789', value: 0.00123456789, format: '#0.###########%' },
1374+
{ text: '0.123456789876', value: 0.00123456789876, format: '#0.##############%' },
1375+
{ text: '0.12345678987654', value: 0.0012345678987654, format: '#0.################%' },
13731376
].forEach(({ text, value, format }) => {
13741377
QUnit.test(`percent format should correctly handle float values, value is ${value}`, function(assert) {
13751378
this.instance.option('format', format ? format : '#0.##%');
@@ -1380,6 +1383,14 @@ QUnit.module('format: percent format', moduleConfig, () => {
13801383
});
13811384
});
13821385

1386+
QUnit.test('It should be possible to use percent format with more than 7 fractional digits (T1277123)', function(assert) {
1387+
this.instance.option('format', '#0.###########%');
1388+
this.keyboard.type('0.123456789').change();
1389+
1390+
assert.strictEqual(this.input.val(), '0.123456789%', 'text is correct');
1391+
assert.strictEqual(this.instance.option('value'), 0.00123456789, 'value is correct');
1392+
});
1393+
13831394
[
13841395
{ text: '0.04', value: 0.00035, format: '#0.00%' },
13851396
{ text: '0.0350', value: 0.00035, format: '#0.0000%' },

0 commit comments

Comments
 (0)