Skip to content

Commit e86b19b

Browse files
[#686] Fix thoushand formatter and number to string fn
1 parent f3c71d1 commit e86b19b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

frontend/src/components/chart/options/Pie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const Pie = ({ data, percentage, chartTitle, extra = {} }) => {
8888
show: true,
8989
length: 15,
9090
length2: 10,
91-
smooth: true,
91+
smooth: false,
9292
lineStyle: {
9393
width: 2,
9494
},

frontend/src/components/chart/options/common.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@ export const thousandFormatter = (value, toFixed = null) => {
44
if (value === null || isNaN(value)) {
55
return 0;
66
}
7+
8+
// Ensure value is a number first
9+
let numValue = typeof value === "string" ? parseFloat(value) : value;
10+
711
if (toFixed !== null) {
8-
value = parseFloat(value)?.toFixed(toFixed);
12+
numValue = parseFloat(numValue.toFixed(toFixed));
913
}
10-
const finalValue = value
11-
? String(value).replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, "$1,")
14+
15+
const finalValue = numValue
16+
? String(numValue).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
1217
: 0;
1318
return finalValue;
1419
};
1520

1621
export const formatNumberToString = (number) => {
17-
// Convert to number if it's a string
18-
const num =
19-
typeof number === "string" ? parseFloat(number.replace(/,/g, "")) : number;
22+
// Handle null/undefined early
23+
if (number === null || typeof number === "undefined") {
24+
return "0";
25+
}
26+
27+
// Convert to number, handling both comma and period separators
28+
let num = number;
29+
if (typeof number === "string") {
30+
// Remove any non-numeric characters except decimal point and minus
31+
num = parseFloat(number.replace(/[^\d.-]/g, ""));
32+
}
33+
num = Number(num);
2034

2135
// Handle invalid numbers
2236
if (isNaN(num)) {

0 commit comments

Comments
 (0)