提供百分比格式化和计算的工具函数。
npx shadcn@latest add https://codebase.anyask.dev/r/utils-percent.json
yarn dlx shadcn@latest add https://codebase.anyask.dev/r/utils-percent.json
pnpm dlx shadcn@latest add https://codebase.anyask.dev/r/utils-percent.json
bunx shadcn@latest add https://codebase.anyask.dev/r/utils-percent.json
deno run npm:shadcn@latest npm:add https://codebase.anyask.dev/r/utils-percent.json
将数值转换为百分比形式,可指定小数位数。
计算两个数值的百分比(numerator / denominator * 100),可指定小数位数。
type FormatNumberInput = string | number | null | undefined;
formatPercent
(value: FormatNumberInput, percent?: number) => string | null
calculatePercentage
(numerator?: FormatNumberInput, denominator?: FormatNumberInput, percent?: number) => string | number | null