mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
parent
f3bdc837ee
commit
cf7521da75
@ -32,7 +32,7 @@ order: 39
|
||||
"type": "page",
|
||||
"body": {
|
||||
"type": "number",
|
||||
"value": 123456.34343434343,
|
||||
"value": 13525646.295,
|
||||
"precision": 2
|
||||
}
|
||||
}
|
||||
|
@ -252,6 +252,15 @@ test('Renderer:number with precision and default value', async () => {
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('Renderer:number with precision and round', async () => {
|
||||
const {input, wrap, container, getByText} = await setup({
|
||||
precision: 2,
|
||||
value: 6.295
|
||||
});
|
||||
|
||||
expect(input.value).toBe('6.30');
|
||||
});
|
||||
|
||||
test('Renderer:number with step & precision & displayMode & keyboard', async () => {
|
||||
const {input, wrap, container, getByText} = await setup({
|
||||
step: 3,
|
||||
|
@ -5,6 +5,13 @@ import {BaseSchema} from '../Schema';
|
||||
import isNumber from 'lodash/isNumber';
|
||||
import {getPropValue, Option, PlainObject, normalizeOptions} from 'amis-core';
|
||||
|
||||
import getMiniDecimal, {
|
||||
DecimalClass,
|
||||
toFixed,
|
||||
getNumberPrecision,
|
||||
num2str
|
||||
} from '@rc-component/mini-decimal';
|
||||
|
||||
/**
|
||||
* Number 展示渲染器。
|
||||
* 文档:https://aisuda.bce.baidu.com/amis/zh-CN/components/number
|
||||
@ -111,7 +118,9 @@ export class NumberField extends React.Component<NumberProps> {
|
||||
viewValue = <span>{value}</span>;
|
||||
} else {
|
||||
if (typeof value === 'number' && precision) {
|
||||
value = value.toFixed(precision);
|
||||
value = getMiniDecimal(
|
||||
toFixed(num2str(value), '.', precision)
|
||||
).toNumber();
|
||||
}
|
||||
|
||||
if (kilobitSeparator) {
|
||||
|
Loading…
Reference in New Issue
Block a user