diff --git a/components/lib/inputnumber/BaseInputNumber.vue b/components/lib/inputnumber/BaseInputNumber.vue index a34e8516a..5dcf61c9b 100644 --- a/components/lib/inputnumber/BaseInputNumber.vue +++ b/components/lib/inputnumber/BaseInputNumber.vue @@ -78,6 +78,23 @@ export default { type: Number, default: undefined }, + roundingMode: { + type: String, + default: 'halfExpand', + validator(value) { + return [ + 'ceil', + 'floor', + 'expand', + 'trunc', + 'halfCeil', + 'halfFloor', + 'halfExpand', + 'halfTrunc', + 'halfEven' + ].includes(value); + } + }, min: { type: Number, default: null diff --git a/components/lib/inputnumber/InputNumber.d.ts b/components/lib/inputnumber/InputNumber.d.ts index 7a15b9d95..f5f7cfbb7 100755 --- a/components/lib/inputnumber/InputNumber.d.ts +++ b/components/lib/inputnumber/InputNumber.d.ts @@ -14,6 +14,17 @@ import { InputTextPassThroughOptions } from '../inputtext'; import { PassThroughOptions } from '../passthrough'; 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 = InputNumberPassThroughAttributes | ((options: InputNumberPassThroughMethodOptions) => 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). */ 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. */ diff --git a/components/lib/inputnumber/InputNumber.vue b/components/lib/inputnumber/InputNumber.vue index fddd1628e..06ac9faae 100755 --- a/components/lib/inputnumber/InputNumber.vue +++ b/components/lib/inputnumber/InputNumber.vue @@ -181,7 +181,8 @@ export default { currencyDisplay: this.currencyDisplay, useGrouping: this.useGrouping, minimumFractionDigits: this.minFractionDigits, - maximumFractionDigits: this.maxFractionDigits + maximumFractionDigits: this.maxFractionDigits, + roundingMode: this.roundingMode, }; }, constructParser() { @@ -225,7 +226,7 @@ export default { }, getCurrencyExpression() { 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'); } @@ -247,7 +248,7 @@ export default { if (this.suffix) { this.suffixChar = this.suffix; } 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]; }