From 8d63ed170a1c8485169a744d69e96b91c957c1ad Mon Sep 17 00:00:00 2001 From: tristanliu Date: Tue, 19 Nov 2024 14:28:29 +0800 Subject: [PATCH] [improvement][headless-fe] Added null-check conditions to the data formatting function. --- webapp/packages/chat-sdk/src/utils/utils.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webapp/packages/chat-sdk/src/utils/utils.ts b/webapp/packages/chat-sdk/src/utils/utils.ts index de8494240..b514a0105 100644 --- a/webapp/packages/chat-sdk/src/utils/utils.ts +++ b/webapp/packages/chat-sdk/src/utils/utils.ts @@ -3,6 +3,9 @@ import { NumericUnit } from '../common/constants'; import { isString } from 'lodash'; export function formatByDecimalPlaces(value: number | string, decimalPlaces: number) { + if (value === null || value === undefined || value === '') { + return 0; + } if (isNaN(+value) || decimalPlaces < 0 || decimalPlaces > 100) { return value; } @@ -17,6 +20,9 @@ export function formatByDecimalPlaces(value: number | string, decimalPlaces: num } export function formatByThousandSeperator(value: number | string) { + if (value === null || value === undefined || value === '') { + return 0; + } if (isNaN(+value)) { return value; }