Skip to content

Commit

Permalink
fix: support float number
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed May 3, 2022
1 parent a298f7c commit bd0907b
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand All @@ -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"));
Expand Down

0 comments on commit bd0907b

Please sign in to comment.