fix: support float number

This commit is contained in:
appflowy 2022-05-03 10:26:42 +08:00
parent a298f7c576
commit bd0907b0a4

View File

@ -85,7 +85,17 @@ impl CellDataOperation for NumberTypeOption {
let cell_data = type_option_cell_data.data;
match self.format {
NumberFormat::Number => cell_data.parse::<i64>().map_or(String::new(), |v| v.to_string()),
NumberFormat::Number => {
if let Ok(v) = cell_data.parse::<f64>() {
return v.to_string();
}
if let Ok(v) = cell_data.parse::<i64>() {
return v.to_string();
}
return String::new();
}
NumberFormat::Percent => cell_data.parse::<f64>().map_or(String::new(), |v| v.to_string()),
_ => self.money_from_str(&cell_data),
}
@ -100,7 +110,8 @@ impl CellDataOperation for NumberTypeOption {
_cell_meta: Option<CellMeta>,
) -> Result<String, FlowyError> {
let changeset = changeset.into();
let data = self.strip_symbol(changeset);
let data = changeset.to_string();
let data = self.strip_symbol(data.trim());
if !data.chars().all(char::is_numeric) {
return Err(FlowyError::invalid_data().context("Should only contain numbers"));