[improvement][headless-fe] Added null-check conditions to the data formatting function.

This commit is contained in:
tristanliu
2024-11-19 14:28:29 +08:00
parent f4f0e58bfb
commit 8d63ed170a

View File

@@ -3,6 +3,9 @@ import { NumericUnit } from '../common/constants';
import { isString } from 'lodash'; import { isString } from 'lodash';
export function formatByDecimalPlaces(value: number | string, decimalPlaces: number) { export function formatByDecimalPlaces(value: number | string, decimalPlaces: number) {
if (value === null || value === undefined || value === '') {
return 0;
}
if (isNaN(+value) || decimalPlaces < 0 || decimalPlaces > 100) { if (isNaN(+value) || decimalPlaces < 0 || decimalPlaces > 100) {
return value; return value;
} }
@@ -17,6 +20,9 @@ export function formatByDecimalPlaces(value: number | string, decimalPlaces: num
} }
export function formatByThousandSeperator(value: number | string) { export function formatByThousandSeperator(value: number | string) {
if (value === null || value === undefined || value === '') {
return 0;
}
if (isNaN(+value)) { if (isNaN(+value)) {
return value; return value;
} }