fix: format number in percent format

This commit is contained in:
appflowy 2022-09-26 17:33:31 +08:00
parent e3a1384f7f
commit 602f7e7b6c
4 changed files with 21 additions and 4 deletions

View File

@ -11,7 +11,10 @@ class NumberFormatBloc extends Bloc<NumberFormatEvent, NumberFormatState> {
event.map(setFilter: (_SetFilter value) {
final List<NumberFormat> formats = List.from(NumberFormat.values);
if (value.filter.isNotEmpty) {
formats.retainWhere((element) => element.title().toLowerCase().contains(value.filter.toLowerCase()));
formats.retainWhere((element) => element
.title()
.toLowerCase()
.contains(value.filter.toLowerCase()));
}
emit(state.copyWith(formats: formats, filter: value.filter));
});
@ -91,7 +94,7 @@ extension NumberFormatExtension on NumberFormat {
case NumberFormat.Percent:
return "Percent";
case NumberFormat.PhilippinePeso:
return "Percent";
return "PhilippinePeso";
case NumberFormat.Pound:
return "Pound";
case NumberFormat.Rand:

View File

@ -70,6 +70,15 @@ define_currency_set!(
symbol: "RUB",
symbol_first: false,
},
PERCENT : {
code: "",
exponent: 2,
locale: EnIn,
minor_units: 1,
name: "percent",
symbol: "%",
symbol_first: false,
},
USD : {
code: "USD",
exponent: 2,
@ -435,7 +444,7 @@ impl NumberFormat {
NumberFormat::Leu => number_currency::RON,
NumberFormat::ArgentinePeso => number_currency::ARS,
NumberFormat::UruguayanPeso => number_currency::UYU,
NumberFormat::Percent => number_currency::USD,
NumberFormat::Percent => number_currency::PERCENT,
}
}

View File

@ -93,6 +93,11 @@ mod tests {
assert_number(&type_option, "€0.5", "€0,5", &field_type, &field_rev);
assert_number(&type_option, "€1844", "€1.844", &field_type, &field_rev);
}
NumberFormat::Percent => {
assert_number(&type_option, "1", "1%", &field_type, &field_rev);
assert_number(&type_option, "10.1", "10.1%", &field_type, &field_rev);
assert_number(&type_option, "100", "100%", &field_type, &field_rev);
}
_ => {}
}
}

View File

@ -77,7 +77,7 @@ impl NumberTypeOptionPB {
pub(crate) fn format_cell_data(&self, s: &str) -> FlowyResult<NumberCellData> {
match self.format {
NumberFormat::Num | NumberFormat::Percent => match Decimal::from_str(s) {
NumberFormat::Num => match Decimal::from_str(s) {
Ok(value, ..) => Ok(NumberCellData::from_decimal(value)),
Err(_) => Ok(NumberCellData::new()),
},