Support roundingMode for InputNumber (#4946)
parent
f16bd6ab2e
commit
078a30720c
|
@ -78,6 +78,23 @@ export default {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: undefined
|
default: undefined
|
||||||
},
|
},
|
||||||
|
roundingMode: {
|
||||||
|
type: String,
|
||||||
|
default: 'halfExpand',
|
||||||
|
validator(value) {
|
||||||
|
return [
|
||||||
|
'ceil',
|
||||||
|
'floor',
|
||||||
|
'expand',
|
||||||
|
'trunc',
|
||||||
|
'halfCeil',
|
||||||
|
'halfFloor',
|
||||||
|
'halfExpand',
|
||||||
|
'halfTrunc',
|
||||||
|
'halfEven'
|
||||||
|
].includes(value);
|
||||||
|
}
|
||||||
|
},
|
||||||
min: {
|
min: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: null
|
default: null
|
||||||
|
|
|
@ -14,6 +14,17 @@ import { InputTextPassThroughOptions } from '../inputtext';
|
||||||
import { PassThroughOptions } from '../passthrough';
|
import { PassThroughOptions } from '../passthrough';
|
||||||
import { ClassComponent, GlobalComponentConstructor, Nullable, PassThrough } from '../ts-helpers';
|
import { ClassComponent, GlobalComponentConstructor, Nullable, PassThrough } from '../ts-helpers';
|
||||||
|
|
||||||
|
export declare type RoundingMode =
|
||||||
|
| 'ceil'
|
||||||
|
| 'floor'
|
||||||
|
| 'expand'
|
||||||
|
| 'trunc'
|
||||||
|
| 'halfCeil'
|
||||||
|
| 'halfFloor'
|
||||||
|
| 'halfExpand'
|
||||||
|
| 'halfTrunc'
|
||||||
|
| 'halfEven';
|
||||||
|
|
||||||
export declare type InputNumberPassThroughOptionType<T = any> = InputNumberPassThroughAttributes | ((options: InputNumberPassThroughMethodOptions<T>) => InputNumberPassThroughAttributes | string) | string | null | undefined;
|
export declare type InputNumberPassThroughOptionType<T = any> = InputNumberPassThroughAttributes | ((options: InputNumberPassThroughMethodOptions<T>) => InputNumberPassThroughAttributes | string) | string | null | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -232,6 +243,11 @@ export interface InputNumberProps {
|
||||||
* the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the [ISO 4217 currency code](https://www.six-group.com/en/products-services/financial-information/data-standards.html#scrollTo=maintenance-agency) list (2 if the list doesn't provide that information).
|
* the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the [ISO 4217 currency code](https://www.six-group.com/en/products-services/financial-information/data-standards.html#scrollTo=maintenance-agency) list (2 if the list doesn't provide that information).
|
||||||
*/
|
*/
|
||||||
maxFractionDigits?: number | undefined;
|
maxFractionDigits?: number | undefined;
|
||||||
|
/**
|
||||||
|
* How decimals should be rounded.
|
||||||
|
* The default value is `"halfExpand"`, [further information](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingmode).
|
||||||
|
*/
|
||||||
|
roundingMode?: RoundingMode;
|
||||||
/**
|
/**
|
||||||
* Mininum boundary value.
|
* Mininum boundary value.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -181,7 +181,8 @@ export default {
|
||||||
currencyDisplay: this.currencyDisplay,
|
currencyDisplay: this.currencyDisplay,
|
||||||
useGrouping: this.useGrouping,
|
useGrouping: this.useGrouping,
|
||||||
minimumFractionDigits: this.minFractionDigits,
|
minimumFractionDigits: this.minFractionDigits,
|
||||||
maximumFractionDigits: this.maxFractionDigits
|
maximumFractionDigits: this.maxFractionDigits,
|
||||||
|
roundingMode: this.roundingMode,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
constructParser() {
|
constructParser() {
|
||||||
|
@ -225,7 +226,7 @@ export default {
|
||||||
},
|
},
|
||||||
getCurrencyExpression() {
|
getCurrencyExpression() {
|
||||||
if (this.currency) {
|
if (this.currency) {
|
||||||
const formatter = new Intl.NumberFormat(this.locale, { style: 'currency', currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
const formatter = new Intl.NumberFormat(this.locale, { style: 'currency', currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0, roundingMode: this.roundingMode });
|
||||||
|
|
||||||
return new RegExp(`[${formatter.format(1).replace(/\s/g, '').replace(this._numeral, '').replace(this._group, '')}]`, 'g');
|
return new RegExp(`[${formatter.format(1).replace(/\s/g, '').replace(this._numeral, '').replace(this._group, '')}]`, 'g');
|
||||||
}
|
}
|
||||||
|
@ -247,7 +248,7 @@ export default {
|
||||||
if (this.suffix) {
|
if (this.suffix) {
|
||||||
this.suffixChar = this.suffix;
|
this.suffixChar = this.suffix;
|
||||||
} else {
|
} else {
|
||||||
const formatter = new Intl.NumberFormat(this.locale, { style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
const formatter = new Intl.NumberFormat(this.locale, { style: this.mode, currency: this.currency, currencyDisplay: this.currencyDisplay, minimumFractionDigits: 0, maximumFractionDigits: 0, roundingMode: this.roundingMode });
|
||||||
|
|
||||||
this.suffixChar = formatter.format(1).split('1')[1];
|
this.suffixChar = formatter.format(1).split('1')[1];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue