Skip to content

Commit 5f18ff7

Browse files
display rounded to unit (#2427)
Signed-off-by: Mathieu DEHARBE <[email protected]>
1 parent 29997c2 commit 5f18ff7

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/components/custom-aggrid/custom-aggrid-header.jsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,31 @@ const styles = {
7070
*/
7171
export function DisplayRounding({ decimalAfterDot }) {
7272
const intl = useIntl();
73+
const roundedTo1 = decimalAfterDot === 0;
7374
const displayAsPower10 = decimalAfterDot > 4;
7475
const baseMessage =
7576
intl.formatMessage({
76-
id: 'filter.rounded',
77+
id: roundedTo1 ? 'filter.roundedToOne' : 'filter.rounded',
7778
}) + ' ';
7879

7980
const decimalAfterDotStr = -decimalAfterDot;
81+
let roundingPrecision = null;
82+
if (!roundedTo1) {
83+
roundingPrecision = displayAsPower10 ? (
84+
<>
85+
10
86+
<Box component="span" sx={styles.exponent}>
87+
{decimalAfterDotStr}
88+
</Box>
89+
</>
90+
) : (
91+
1 / Math.pow(10, decimalAfterDot)
92+
);
93+
}
8094
return (
8195
<FormHelperText>
8296
{baseMessage}
83-
{displayAsPower10 ? (
84-
<>
85-
10
86-
<Box component="span" sx={styles.exponent}>
87-
{decimalAfterDotStr}
88-
</Box>
89-
</>
90-
) : (
91-
1 / Math.pow(10, decimalAfterDot)
92-
)}
97+
{roundingPrecision}
9398
</FormHelperText>
9499
);
95100
}
@@ -491,7 +496,7 @@ const CustomHeaderComponent = ({
491496
}}
492497
/>
493498
</Grid>
494-
{isNumberInput && decimalAfterDot > 0 ? (
499+
{isNumberInput && selectedFilterData ? (
495500
<Grid item>
496501
<DisplayRounding decimalAfterDot={decimalAfterDot} />
497502
</Grid>

src/translations/dynamic/filter-locale-en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const filter_locale_en = {
1717
'filter.greaterThan': 'Greater than',
1818
'filter.filterOoo': 'Filter...',
1919
'filter.rounded': 'Rounded to',
20+
'filter.roundedToOne': 'Rounded to the nearest unit.',
2021
'filter.warnRounding': 'From 13 decimal places after the comma, filters become imprecise.',
2122
};
2223

src/translations/dynamic/filter-locale-fr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const filter_locale_fr = {
1717
'filter.greaterThan': 'Supérieur',
1818
'filter.filterOoo': 'Filtrer...',
1919
'filter.rounded': 'Arrondi à',
20+
'filter.roundedToOne': "Arrondi à l'unité.",
2021
'filter.warnRounding': 'À partir de 13 décimales après la virgule, les filtres deviennent imprécis.',
2122
};
2223

0 commit comments

Comments
 (0)