Skip to content

Commit

Permalink
Fix parameter formatting (#7934)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat authored Aug 20, 2024
1 parent 5515e07 commit 8c6275b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/frontend/src/defaults/formatters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/frontend/src/tables/part/ParametricPartTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -80,7 +82,7 @@ function ParameterCell({
value={value ?? '-'}
extra={extra}
icon={hovered && canEdit ? 'edit' : 'info'}
title={t`Internal Units`}
title={template.name}
/>
</Group>
</Group>
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/src/tables/part/PartParameterTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 8c6275b

Please sign in to comment.