Skip to content

Commit 602f7e7

Browse files
committed
fix: format number in percent format
1 parent e3a1384 commit 602f7e7

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

frontend/app_flowy/lib/plugins/grid/application/field/type_option/number_format_bloc.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class NumberFormatBloc extends Bloc<NumberFormatEvent, NumberFormatState> {
1111
event.map(setFilter: (_SetFilter value) {
1212
final List<NumberFormat> formats = List.from(NumberFormat.values);
1313
if (value.filter.isNotEmpty) {
14-
formats.retainWhere((element) => element.title().toLowerCase().contains(value.filter.toLowerCase()));
14+
formats.retainWhere((element) => element
15+
.title()
16+
.toLowerCase()
17+
.contains(value.filter.toLowerCase()));
1518
}
1619
emit(state.copyWith(formats: formats, filter: value.filter));
1720
});
@@ -91,7 +94,7 @@ extension NumberFormatExtension on NumberFormat {
9194
case NumberFormat.Percent:
9295
return "Percent";
9396
case NumberFormat.PhilippinePeso:
94-
return "Percent";
97+
return "PhilippinePeso";
9598
case NumberFormat.Pound:
9699
return "Pound";
97100
case NumberFormat.Rand:

frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/format.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ define_currency_set!(
7070
symbol: "RUB",
7171
symbol_first: false,
7272
},
73+
PERCENT : {
74+
code: "",
75+
exponent: 2,
76+
locale: EnIn,
77+
minor_units: 1,
78+
name: "percent",
79+
symbol: "%",
80+
symbol_first: false,
81+
},
7382
USD : {
7483
code: "USD",
7584
exponent: 2,
@@ -435,7 +444,7 @@ impl NumberFormat {
435444
NumberFormat::Leu => number_currency::RON,
436445
NumberFormat::ArgentinePeso => number_currency::ARS,
437446
NumberFormat::UruguayanPeso => number_currency::UYU,
438-
NumberFormat::Percent => number_currency::USD,
447+
NumberFormat::Percent => number_currency::PERCENT,
439448
}
440449
}
441450

frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ mod tests {
9393
assert_number(&type_option, "€0.5", "€0,5", &field_type, &field_rev);
9494
assert_number(&type_option, "€1844", "€1.844", &field_type, &field_rev);
9595
}
96+
NumberFormat::Percent => {
97+
assert_number(&type_option, "1", "1%", &field_type, &field_rev);
98+
assert_number(&type_option, "10.1", "10.1%", &field_type, &field_rev);
99+
assert_number(&type_option, "100", "100%", &field_type, &field_rev);
100+
}
96101
_ => {}
97102
}
98103
}

frontend/rust-lib/flowy-grid/src/services/field/type_options/number_type_option/number_type_option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl NumberTypeOptionPB {
7777

7878
pub(crate) fn format_cell_data(&self, s: &str) -> FlowyResult<NumberCellData> {
7979
match self.format {
80-
NumberFormat::Num | NumberFormat::Percent => match Decimal::from_str(s) {
80+
NumberFormat::Num => match Decimal::from_str(s) {
8181
Ok(value, ..) => Ok(NumberCellData::from_decimal(value)),
8282
Err(_) => Ok(NumberCellData::new()),
8383
},

0 commit comments

Comments
 (0)