add formatterExtra for big fraction part

This commit is contained in:
Chika 2022-07-08 19:24:21 +03:00
parent c03cba23fd
commit 46d63e490c
2 changed files with 16 additions and 6 deletions

View File

@ -1,7 +1,7 @@
import { MAX_FRANCHISE, MAX_LEASING_PERIOD } from 'constants/values';
import DownloadOutlined from 'Elements/icons/DownloadOutlined';
import date from 'tools/date';
import { formatter, parser } from 'tools/number';
import { formatter, formatterExtra, parser } from 'tools/number';
import type { ElementsProps } from './elements-components';
const props: Partial<ElementsProps> = {
@ -71,7 +71,7 @@ const props: Partial<ElementsProps> = {
max: 50,
precision: 4,
parser,
formatter,
formatter: formatterExtra,
addonAfter: '%',
},
tbxFirstPaymentRub: {
@ -89,7 +89,7 @@ const props: Partial<ElementsProps> = {
step: 1,
precision: 6,
parser,
formatter,
formatter: formatterExtra,
addonAfter: '%',
},
tbxLastPaymentRub: {
@ -191,7 +191,7 @@ const props: Partial<ElementsProps> = {
step: 0.5,
precision: 4,
parser,
formatter,
formatter: formatterExtra,
addonAfter: 'л',
},
tbxMaxMass: {
@ -341,7 +341,7 @@ const props: Partial<ElementsProps> = {
step: 0.0001,
precision: 6,
parser,
formatter,
formatter: formatterExtra,
addonAfter: '%',
},
linkDownloadKp: {

View File

@ -1,6 +1,16 @@
/* eslint-disable implicit-arrow-linebreak */
export function parser(value?: string) {
const normalized = (value || '0').replace(/\s/g, '').replaceAll(',', '.');
return Number.parseFloat(normalized);
}
export const formatter = (value?: number) => Intl.NumberFormat('ru').format(value || 0);
export const formatter = (value?: number) =>
Intl.NumberFormat('ru', {
minimumFractionDigits: 2,
}).format(value || 0);
export const formatterExtra = (value?: number) =>
Intl.NumberFormat('ru', {
minimumFractionDigits: 2,
maximumFractionDigits: 6,
}).format(value || 0);