36 lines
963 B
TypeScript
36 lines
963 B
TypeScript
/* eslint-disable func-style */
|
|
|
|
export function parser(value?: string) {
|
|
if (!value) return 0;
|
|
|
|
// eslint-disable-next-line unicorn/prefer-string-replace-all, require-unicode-regexp
|
|
const normalized = value.replace(/\s/g, '').replaceAll(',', '.');
|
|
|
|
return Number.parseFloat(normalized);
|
|
}
|
|
export const formatter = (value?: number) =>
|
|
Intl.NumberFormat('ru', {
|
|
minimumFractionDigits: 2,
|
|
}).format(value || 0);
|
|
|
|
export const formatterExtra = (value?: number) =>
|
|
Intl.NumberFormat('ru', {
|
|
maximumFractionDigits: 6,
|
|
minimumFractionDigits: 2,
|
|
}).format(value || 0);
|
|
|
|
export const moneyFormatter = Intl.NumberFormat('ru', {
|
|
currency: 'RUB',
|
|
style: 'currency',
|
|
}).format;
|
|
|
|
export const percentFormatter = Intl.NumberFormat('ru', {
|
|
maximumFractionDigits: 2,
|
|
minimumFractionDigits: 2,
|
|
style: 'percent',
|
|
}).format;
|
|
|
|
export function round(value: number, precision: number = 0) {
|
|
return Number.parseFloat(value.toFixed(precision));
|
|
}
|