mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
10 lines
354 B
TypeScript
10 lines
354 B
TypeScript
export type DistanceUnit = 'km' | 'mi';
|
|
|
|
const METRES_PER_MILE = 1609.344;
|
|
|
|
export const formatDistance = (metres: number, unit: DistanceUnit = 'km'): string => {
|
|
const value = unit === 'mi' ? metres / METRES_PER_MILE : metres / 1000;
|
|
const rounded = value < 10 ? value.toFixed(1) : String(Math.round(value));
|
|
return `${rounded} ${unit}`;
|
|
};
|