Files
sibedas/resources/js/global-config.js
Firman Herdiansyah 7e99d547c8 Update Config
2025-02-06 10:49:16 +07:00

29 lines
892 B
JavaScript

const GlobalConfig = {
apiHost: "http://147.93.121.38/",
};
export default GlobalConfig;
export function addThousandSeparators(value, fractionDigits = 2) {
if (!value) return null; // Handle empty or null values
// Remove any non-numeric characters except commas and dots
value = value.replace(/[^0-9,.]/g, "");
// If the value contains multiple dots, assume dots are thousand separators
if ((value.match(/\./g) || []).length > 1) {
value = value.replace(/\./g, "");
}
// Convert to a proper decimal number
let number = parseFloat(value.replace(",", "."));
if (isNaN(number)) return null; // Return null if conversion fails
// Format the number with thousand separators
return new Intl.NumberFormat("en-US", {
minimumFractionDigits: fractionDigits,
maximumFractionDigits: fractionDigits,
}).format(number);
}