Skip to content

Commit

Permalink
Support roundingMode for InputNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
trandaison authored and melloware committed Dec 6, 2023
1 parent 031d360 commit 45c0cf9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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
16 changes: 16 additions & 0 deletions components/lib/inputnumber/inputnumber.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ 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 +201,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

0 comments on commit 45c0cf9

Please sign in to comment.