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:
@@ -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' });
|
||||
|
||||
Reference in New Issue
Block a user