Fixed an error where toFixed() wouldn't round correctly. Added a util function that does a better job (at least for 2 digits precision)

This commit is contained in:
2025-10-29 10:24:39 +01:00
parent da73a18bf9
commit 039ffa6f2e
3 changed files with 10 additions and 6 deletions
+6 -1
View File
@@ -7,13 +7,14 @@ export function cn(...inputs: ClassValue[]) {
}
export function urlIsActive(urlToCheck: NonNullable<InertiaLinkProps['href']>, currentUrl: string) {
return toUrl(urlToCheck) === currentUrl;
return currentUrl.indexOf(toUrl(urlToCheck)) >= 0
}
export function toUrl(href: NonNullable<InertiaLinkProps['href']>) {
return typeof href === 'string' ? href : href?.url;
}
const currencyFormatter = new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR',
@@ -25,6 +26,10 @@ export function toCurrency(value: number | undefined) {
return currencyFormatter.format(value);
}
export function toFixedRounded(num: number, precision: number): number {
return Number((Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision)).toFixed(precision))
}
export function toLocalDate(value: string) {
const date = new Date(value);
return date.toLocaleDateString('de-DE', { day: '2-digit', month: 'short', year: 'numeric' });