Skip to content

Commit

Permalink
Fix Money.from_str underscore parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 27, 2024
1 parent 5369328 commit 6fe3ae3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nautilus_core/model/src/types/money.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl FromStr for Money {

// Parse amount
let amount = parts[0]
.replace('_', "")
.parse::<f64>()
.map_err(|e| format!("Cannot parse amount '{}' as `f64`: {:?}", parts[0], e))?;

Expand Down Expand Up @@ -388,6 +389,7 @@ mod tests {
#[case("0 USD", Currency::USD(), dec!(0.00))]
#[case("1.1 AUD", Currency::AUD(), dec!(1.10))]
#[case("1.12345678 BTC", Currency::BTC(), dec!(1.12345678))]
#[case("10_000.10 USD", Currency::USD(), dec!(10000.10))]
fn test_from_str_valid_input(
#[case] input: &str,
#[case] expected_currency: Currency,
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/model/objects/test_money.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def test_from_raw_given_valid_values_returns_expected_result(
["1.00 USDT", Money(1.00, USDT)],
["1.00 USD", Money(1.00, USD)],
["1.001 AUD", Money(1.00, AUD)],
["10_001.01 AUD", Money(10001.01, AUD)],
],
)
def test_from_str_given_valid_strings_returns_expected_result(
Expand Down

0 comments on commit 6fe3ae3

Please sign in to comment.