mirror of
https://framagit.org/enfance-libre/statistiques
synced 2025-12-07 07:23:44 +00:00
22 lines
661 B
TypeScript
22 lines
661 B
TypeScript
import { StatsValue } from "../statistiques/v2/desc/StatsDesc";
|
|
import { ValueFormatOptions } from "./ValueFormatOptions";
|
|
|
|
export function formatValue(
|
|
value: StatsValue,
|
|
valueFormatOptions: ValueFormatOptions
|
|
) {
|
|
if (value === undefined) {
|
|
return "Pas de données";
|
|
}
|
|
const valueStr = value.toLocaleString("fr-FR", {
|
|
useGrouping: false,
|
|
maximumFractionDigits:
|
|
valueFormatOptions.valueMaxFractioDigits === undefined
|
|
? 1
|
|
: valueFormatOptions.valueMaxFractioDigits,
|
|
});
|
|
const formattedValue = `${valueStr}${
|
|
valueFormatOptions.unit === undefined ? "" : valueFormatOptions.unit
|
|
}`;
|
|
return formattedValue;
|
|
}
|