Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344const km = new Intl.NumberFormat('fr-FR', { maximumFractionDigits: 1 })
/** `1234` → « 1,2 km », `850` → « 850 m ». */export function formatDistance(meters: number): string { if (meters < 1000) return `${Math.round(meters)} m` return `${km.format(meters / 1000)} km`}
/** `8100` → « 2 h 15 », `2700` → « 45 min ». */export function formatDuration(seconds: number): string { const total = Math.round(seconds / 60) const h = Math.floor(total / 60) const min = total % 60 if (h === 0) return `${Math.max(min, 1)} min` return min === 0 ? `${h} h` : `${h} h ${String(min).padStart(2, '0')}`}
/** `12` → « 12 virages », `0` → « aucun virage ». */export function formatBends(count: number): string { if (count === 0) return 'aucun virage' return `${count} virage${count > 1 ? 's' : ''}`}
const currency = new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' })
/** `41.3` → « 41,30 € ». */export function formatEuros(value: number): string { return currency.format(value)}
const bytes = new Intl.NumberFormat('fr-FR', { maximumFractionDigits: 0 })const tenths = new Intl.NumberFormat('fr-FR', { maximumFractionDigits: 1 })
/** * `58_400_000` → « 58 Mo ». Les mégaoctets décimaux, comme les annoncent les * navigateurs et les fabricants ; sous dix, une décimale, car la différence * entre 2 et 2,4 Mo se voit sur un forfait. */export function formatBytes(value: number): string { const mo = value / 1e6 if (mo < 1) return `${bytes.format(Math.max(1, Math.round(value / 1e3)))} ko` return `${(mo < 10 ? tenths : bytes).format(mo)} Mo`}