mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
891 B
30 lines
891 B
export const precisions = [ |
|
{ id: 0, title: '1' }, |
|
{ id: 1, title: '1.0' }, |
|
{ id: 2, title: '1.00' }, |
|
{ id: 3, title: '1.000' }, |
|
{ id: 4, title: '1.0000' }, |
|
{ id: 5, title: '1.00000' }, |
|
{ id: 6, title: '1.000000' }, |
|
{ id: 7, title: '1.0000000' }, |
|
{ id: 8, title: '1.00000000' }, |
|
] |
|
|
|
export function renderPercent(value: any, precision: number, withPercentSymbol = true) { |
|
if (!value) return value |
|
value = (Number(value) * 100).toFixed(precision) |
|
if (withPercentSymbol) return padPercentSymbol(value) |
|
return value |
|
} |
|
|
|
export function isValidPercent(value: any, negative: boolean): boolean { |
|
return negative ? /^-?\d{1,20}(\.\d+)?$/.test(value) : /^\d{1,20}(\.\d+)?$/.test(value) |
|
} |
|
|
|
export function getPercentStep(precision: number): string { |
|
return (1 / 10 ** precision).toString() |
|
} |
|
|
|
function padPercentSymbol(value: any) { |
|
return value ? `${value}%` : value |
|
}
|
|
|