mirror of
https://github.com/youzan/vant.git
synced 2026-01-13 07:03:44 +08:00
fix(Stepper): format scientific number (#13709)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user