bank/components/Percentage.tsx
2024-08-24 11:31:45 -05:00

24 lines
531 B
TypeScript

const percentageFormat = new Intl.NumberFormat('en-US', {
currency: 'USD',
maximumFractionDigits: 2,
})
export function percentage(ratio: number): string {
return percentageFormat.format(ratio * 100) + '%'
}
export function clamp(min: number, val: number, max: number): number {
return Math.max(min, Math.min(max, val))
}
export function Percentage(
{ ratio, ...props }:
& { ratio: number }
& JSX.HTMLAttributes<HTMLSpanElement>,
) {
return (
<span class='font-mono' {...props}>
{percentage(ratio)}
</span>
)
}