Fix parameter formatting (#7934)

This commit is contained in:
Oliver 2024-08-20 18:20:29 +10:00 committed by GitHub
parent 5515e0762e
commit 8c6275b845
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -30,7 +30,11 @@ export function formatDecimal(
return value;
}
let formatter = new Intl.NumberFormat(locale);
let formatter = new Intl.NumberFormat(locale, {
style: 'decimal',
maximumFractionDigits: options.digits ?? 6,
minimumFractionDigits: options.minDigits ?? 0
});
return formatter.format(value);
}

View File

@ -8,6 +8,7 @@ import { useNavigate } from 'react-router-dom';
import { api } from '../../App';
import { YesNoButton } from '../../components/buttons/YesNoButton';
import { ApiFormFieldSet } from '../../components/forms/fields/ApiFormField';
import { formatDecimal } from '../../defaults/formatters';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { ModelType } from '../../enums/ModelType';
import { UserRoles } from '../../enums/Roles';
@ -65,7 +66,8 @@ function ParameterCell({
parameter.data_numeric &&
parameter.data_numeric != parameter.data
) {
extra.push(`${parameter.data_numeric} [${template.units}]`);
const numeric = formatDecimal(parameter.data_numeric, { digits: 15 });
extra.push(`${numeric} [${template.units}]`);
}
if (hovered && canEdit) {
@ -80,7 +82,7 @@ function ParameterCell({
value={value ?? '-'}
extra={extra}
icon={hovered && canEdit ? 'edit' : 'info'}
title={t`Internal Units`}
title={template.name}
/>
</Group>
</Group>

View File

@ -6,6 +6,7 @@ import { useCallback, useMemo, useState } from 'react';
import { AddItemButton } from '../../components/buttons/AddItemButton';
import { YesNoButton } from '../../components/buttons/YesNoButton';
import { ApiFormFieldSet } from '../../components/forms/fields/ApiFormField';
import { formatDecimal } from '../../defaults/formatters';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { UserRoles } from '../../enums/Roles';
import { usePartParameterFields } from '../../forms/PartForms';
@ -85,7 +86,8 @@ export function PartParameterTable({
record.data_numeric &&
record.data_numeric != record.data
) {
extra.push(`${record.data_numeric} [${template.units}]`);
const numeric = formatDecimal(record.data_numeric, { digits: 15 });
extra.push(`${numeric} [${template.units}]`);
}
return (