fix: euro currency number format (#3115)

This commit is contained in:
Richard Shiue 2023-08-07 17:49:03 +08:00 committed by GitHub
parent c6401da0b5
commit fbb1753350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -80,6 +80,18 @@ mod tests {
assert_number(&type_option, "0.2", "$0.2", &field_type, &field);
}
#[test]
fn euro_type_option_test() {
let field_type = FieldType::Number;
let mut type_option = NumberTypeOption::new();
type_option.format = NumberFormat::EUR;
let field = FieldBuilder::new(field_type.clone(), type_option.clone()).build();
assert_number(&type_option, "0.2", "€0,2", &field_type, &field);
assert_number(&type_option, "1000", "€1.000", &field_type, &field);
assert_number(&type_option, "1234.56", "€1.234,56", &field_type, &field);
}
fn assert_number(
type_option: &NumberTypeOption,
input_str: &str,

View File

@ -219,7 +219,7 @@ impl CellDataChangeset for NumberTypeOption {
NumberCellData::from(formatter.to_string()),
)),
_ => Ok((
NumberCellData::from(formatter.to_string()).into(),
NumberCellData::from(formatter.to_unformatted_string()).into(),
NumberCellData::from(formatter.to_string()),
)),
}

View File

@ -7,7 +7,7 @@ use rust_decimal::Decimal;
use rusty_money::Money;
use std::str::FromStr;
#[derive(Default)]
#[derive(Debug, Default)]
pub struct NumberCellFormat {
decimal: Option<Decimal>,
money: Option<String>,
@ -68,6 +68,13 @@ impl NumberCellFormat {
pub fn is_empty(&self) -> bool {
self.decimal.is_none()
}
pub fn to_unformatted_string(&self) -> String {
match self.decimal {
None => String::default(),
Some(decimal) => decimal.to_string(),
}
}
}
fn auto_fill_zero_at_start_if_need(num_str: &str) -> String {