Skip to content

Commit

Permalink
Remove decimal grouping. (#1753)
Browse files Browse the repository at this point in the history
  • Loading branch information
SAnatoliiS authored Apr 18, 2023
1 parent b864818 commit 5833230
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
16 changes: 2 additions & 14 deletions casts/numbers/src/Numbers/UIAnimatedNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export function UIAnimatedNumber({
const diff = React.useRef(new BigNumber(0));

const progress = useSharedValue(0);
const { decimal: decimalSeparator, grouping: integerGroupChar } =
uiLocalized.localeInfo.numbers;
const { grouping: integerGroupChar } = uiLocalized.localeInfo.numbers;

const decimalDigitCount = React.useMemo(() => {
return getDecimalPartDigitCount(value, decimalAspect);
Expand All @@ -60,7 +59,6 @@ export function UIAnimatedNumber({
value,
decimalAspect,
decimalDigitCount,
decimalSeparator,
integerGroupChar,
showPositiveSign,
),
Expand All @@ -74,7 +72,6 @@ export function UIAnimatedNumber({
valueHolder.current,
decimalAspect,
decimalDigitCount,
decimalSeparator,
integerGroupChar,
showPositiveSign,
);
Expand All @@ -89,7 +86,6 @@ export function UIAnimatedNumber({
formatted,
decimalAspect,
decimalDigitCount,
decimalSeparator,
integerGroupChar,
showPositiveSign,
],
Expand Down Expand Up @@ -121,19 +117,11 @@ export function UIAnimatedNumber({
newValue,
decimalAspect,
decimalDigitCount,
decimalSeparator,
integerGroupChar,
showPositiveSign,
);
},
[
formatted,
decimalAspect,
decimalDigitCount,
decimalSeparator,
integerGroupChar,
showPositiveSign,
],
[formatted, decimalAspect, decimalDigitCount, integerGroupChar, showPositiveSign],
);

useAnimatedReaction(
Expand Down
6 changes: 2 additions & 4 deletions casts/numbers/src/Numbers/UIStaticNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,18 @@ export function UIStaticNumber({
showPositiveSign,
}: UINumberGeneralProps &
UINumberAppearance & { sign?: React.ReactNode; signBeforeNumber?: boolean }) {
const { decimal: decimalSeparator, grouping: integerGroupChar } =
uiLocalized.localeInfo.numbers;
const { grouping: integerGroupChar } = uiLocalized.localeInfo.numbers;

const formatted = React.useMemo(() => {
const decimalDigitCount = getDecimalPartDigitCount(value, decimalAspect);
return localizedNumberFormat(
value,
decimalAspect,
decimalDigitCount,
decimalSeparator,
integerGroupChar,
showPositiveSign,
);
}, [value, decimalAspect, decimalSeparator, integerGroupChar, showPositiveSign]);
}, [value, decimalAspect, integerGroupChar, showPositiveSign]);

/**
* A dirty hack to respect default font scale setting of `Text`,
Expand Down
12 changes: 1 addition & 11 deletions casts/numbers/src/Numbers/localizedNumberFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ enum Rounding {
// TODO: move it to uiLocalized!
// @inline
const INTEGER_GROUP_SIZE = 3;
// @inline
const DECIMAL_GROUP_SIZE = 3;

function getIntegerSign(integer: BigNumber, showPositiveSign?: boolean) {
'worklet';
Expand All @@ -56,7 +54,6 @@ function getIntegerSign(integer: BigNumber, showPositiveSign?: boolean) {
export function formatNumber(
value: BigNumber,
decimalDigitCount: number,
decimalSeparator: string,
integerGroupChar: string,
showPositiveSign?: boolean,
) {
Expand All @@ -74,11 +71,7 @@ export function formatNumber(
// if it's negative it would be `-0,` or `-0.`
const decimal = value.minus(integer);
const decimalFormatted = decimal
.toFormat(decimalDigitCount, Rounding.RoundDown, {
decimalSeparator,
fractionGroupSize: DECIMAL_GROUP_SIZE,
fractionGroupSeparator: ' ',
})
.toFormat(decimalDigitCount, Rounding.RoundDown)
.slice(decimal.lt(0) ? 2 : 1);

return {
Expand All @@ -91,15 +84,13 @@ export function formatNumber(
* @param value number to format
* @param decimalAspect predefined aspects how to format number
* @param decimalDigitCount count of digits in decimal part of the number
* @param decimalSeparator localized separator from user's device
* @param integerGroupChar localized char for group from user's device
* @returns formatter number as string
*/
export function localizedNumberFormat(
value: BigNumber,
decimalAspect: UINumberDecimalAspect,
decimalDigitCount: number,
decimalSeparator: string,
integerGroupChar: string,
showPositiveSign: boolean | undefined,
) {
Expand All @@ -108,7 +99,6 @@ export function localizedNumberFormat(
const { integer: integerFormatted, decimal: decimalFormatted } = formatNumber(
value,
decimalDigitCount,
decimalSeparator,
integerGroupChar,
showPositiveSign,
);
Expand Down

0 comments on commit 5833230

Please sign in to comment.