Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support roundingMode for InputNumber #5525

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions components/lib/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export const InputNumber = React.memo(
currencyDisplay: props.currencyDisplay,
useGrouping: props.useGrouping,
minimumFractionDigits: props.minFractionDigits,
maximumFractionDigits: props.maxFractionDigits
maximumFractionDigits: props.maxFractionDigits,
roundingMode: props.roundingMode
};
};

Expand Down Expand Up @@ -108,7 +109,8 @@ export const InputNumber = React.memo(
currency: props.currency,
currencyDisplay: props.currencyDisplay,
minimumFractionDigits: 0,
maximumFractionDigits: 0
maximumFractionDigits: 0,
roundingMode: props.roundingMode
});

return new RegExp(`[${formatter.format(1).replace(/\s/g, '').replace(_numeral.current, '').replace(_group.current, '')}]`, 'g');
Expand Down Expand Up @@ -138,7 +140,8 @@ export const InputNumber = React.memo(
currency: props.currency,
currencyDisplay: props.currencyDisplay,
minimumFractionDigits: 0,
maximumFractionDigits: 0
maximumFractionDigits: 0,
roundingMode: props.roundingMode
});

suffixChar.current = formatter.format(1).split('1')[1];
Expand Down
1 change: 1 addition & 0 deletions components/lib/inputnumber/InputNumberBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export const InputNumberBase = ComponentBase.extend({
prefix: null,
readOnly: false,
required: false,
roundingMode: undefined,
showButtons: false,
size: null,
step: 1,
Expand Down
7 changes: 7 additions & 0 deletions components/lib/inputnumber/inputnumber.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { TooltipOptions } from '../tooltip/tooltipoptions';
import { FormEvent } from '../ts-helpers';
import { IconType, PassThroughType } from '../utils/utils';

export declare type RoundingMode = 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfCeil' | 'halfFloor' | 'halfExpand' | 'halfTrunc' | 'halfEven';

export declare type InputNumberPassThroughType<T> = PassThroughType<T, InputNumberPassThroughMethodOptions>;

/**
Expand Down Expand Up @@ -190,6 +192,11 @@ export interface InputNumberProps extends Omit<React.DetailedHTMLProps<React.HTM
* the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the [ISO 4217 currency code list](https://www.six-group.com/en/products-services/financial-information/data-standards.html#scrollTo=maintenance-agency) (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;
/**
* Name of the input element.
*/
Expand Down
Loading