2025-06-16 10:29:41 +02:00
|
|
|
import { StatsValue } from "../statistiques/v2/desc/StatsDesc";
|
2024-09-05 09:23:27 +02:00
|
|
|
import { ValueFormatOptions } from "./ValueFormatOptions";
|
2024-06-04 10:50:16 +02:00
|
|
|
|
2024-10-14 15:51:24 +02:00
|
|
|
export function formatValue(
|
2025-06-16 10:29:41 +02:00
|
|
|
value: StatsValue,
|
2024-10-14 15:51:24 +02:00
|
|
|
valueFormatOptions: ValueFormatOptions
|
|
|
|
|
) {
|
2025-06-16 10:29:41 +02:00
|
|
|
if (value === undefined) {
|
|
|
|
|
return "Pas de données";
|
|
|
|
|
}
|
2024-06-04 10:50:16 +02:00
|
|
|
const valueStr = value.toLocaleString("fr-FR", {
|
|
|
|
|
useGrouping: false,
|
|
|
|
|
maximumFractionDigits:
|
2024-10-14 15:51:24 +02:00
|
|
|
valueFormatOptions.valueMaxFractioDigits === undefined
|
2024-06-04 10:50:16 +02:00
|
|
|
? 1
|
2024-10-14 15:51:24 +02:00
|
|
|
: valueFormatOptions.valueMaxFractioDigits,
|
2024-06-04 10:50:16 +02:00
|
|
|
});
|
|
|
|
|
const formattedValue = `${valueStr}${
|
2024-10-14 15:51:24 +02:00
|
|
|
valueFormatOptions.unit === undefined ? "" : valueFormatOptions.unit
|
2024-06-04 10:50:16 +02:00
|
|
|
}`;
|
|
|
|
|
return formattedValue;
|
|
|
|
|
}
|