Skip to content

Commit

Permalink
fix: fix currency ai (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caedman Ziwen Lan authored Nov 16, 2023
1 parent 7bf9667 commit 4fa9e39
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,20 @@ export const formatterValue = (field, value, notFormatter = true): string | numb
const isPercent = validType(FieldType.Percent);
const isDate = validType(FieldType.DateTime);
const isFomula = validType(FieldType.Formula);
const isNumber = validType(FieldType.Number) || property.valueType === FieldType.Number;
const isNumberType = validType(FieldType.Number) || property.valueType === FieldType.Number;
const precision = property?.precision ?? property?.format?.format?.precision ?? 1;
if (isCurrency) {
return `${fieldSymbol} ${value.toFixed(precision)}`;
try {
const textValue = isNumber(value) ? value.toFixed(precision) : parseFloat(value).toFixed(precision);
return `${fieldSymbol} ${textValue}`;
}catch (e) {
console.error('parse currency' , e);
return `${fieldSymbol} ${String(value)}`;
}
}

// Percentages, numbers with units.
if (isPercent || isNumber) {
if (isPercent || isNumberType) {
const suffixSymbol = isPercent ? '%' : fieldSymbol;
return `${Number(value).toFixed(precision)} ${suffixSymbol}`;
}
Expand Down

0 comments on commit 4fa9e39

Please sign in to comment.