Correct number format

This commit is contained in:
Viet Anh Nguyen 2024-03-07 16:18:06 +07:00
parent dc9f7c00d6
commit c14b139142
2 changed files with 12 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import { useReportList } from 'queries/report';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { downloadReport } from 'request/report';
import { formatPercent, ensureMin, ensureMax } from 'utils/metric-format';
import { formatPercent, ensureMin, ensureMax, formatNumber } from 'utils/metric-format';
import { datetimeStrToDate } from 'utils/time';
@ -125,7 +125,7 @@ const ReportTable: React.FC = () => {
const isAbnormal = ensureMin(record['IMEI Acc'], 0.95);
return (
<span style={{ color: isAbnormal ? 'red' : '' }}>
{formatPercent(Number(record['IMEI Acc']))}
{formatPercent(record['IMEI Acc'])}
</span>
);
},
@ -138,20 +138,20 @@ const ReportTable: React.FC = () => {
const isAbnormal = ensureMin(record['Avg. Accuracy'], 0.95);
return (
<span style={{ color: isAbnormal ? 'red' : '' }}>
{formatPercent(Number(record['Avg. Accuracy']))}
{formatPercent(record['Avg. Accuracy'])}
</span>
);
},
},
{
title: 'Avg. OCR Processing Time',
title: 'Avg. OCR Processing Time (ms)',
dataIndex: 'Avg. OCR Processing Time',
key: 'Avg. OCR Processing Time',
render: (_, record) => {
const isAbnormal = ensureMax(record['Avg. OCR Processing Time'], 2);
return (
<span style={{ color: isAbnormal ? 'red' : '' }}>
{Number(record['Avg. OCR Processing Time'])?.toFixed(2)}
{formatNumber(record['Avg. OCR Processing Time'], 1)}
</span>
);
},

View File

@ -8,6 +8,13 @@ export const formatPercent = (value: any, floatingPoint: number = 1, maskZero: b
return value.toFixed(floatingPoint);
};
export const formatNumber = (value: any, floatingPoint: number = 1, maskZero: boolean = false) => {
if (value === null || value === undefined || (value === 0 && maskZero)) {
return '-';
}
return value.toFixed(floatingPoint);
};
export const ensureMin = (
value: number,
min: number,