fix(Stepper): format scientific number (#13709)

This commit is contained in:
pany
2025-12-13 21:43:03 +08:00
committed by GitHub
parent 7a9d9fcf41
commit 7d935d26a1
2 changed files with 32 additions and 0 deletions

View File

@@ -91,6 +91,11 @@ export default defineComponent({
return value;
}
// format scientific number
if (typeof value === 'number' && String(value).includes('e')) {
value = value.toFixed(decimalLength ? +decimalLength : 17); // 17 is the max precision of a JS number
}
value = formatNumber(String(value), !props.integer);
value = value === '' ? 0 : +value;
value = Number.isNaN(value) ? +min : value;

View File

@@ -455,3 +455,30 @@ test('should allow input be to empty when using allow-empty prop', async () => {
await input.trigger('blur');
expect(wrapper.emitted('update:modelValue')![0]).toEqual([1]);
});
test('scientific number', async () => {
const wrapper = mount(Stepper, {
props: {
min: 0,
modelValue: 9.9e-7,
},
});
const input = wrapper.find('input');
expect(input.element.value).toEqual('9.9e-7');
});
test('scientific number with decimal length', async () => {
const wrapper = mount(Stepper, {
props: {
min: 0,
modelValue: 9.9e-7,
decimalLength: 8,
},
});
const input = wrapper.find('input');
expect(input.element.value).toEqual('0.00000099');
});