Skip to content

Commit

Permalink
chore: use BigDecimal insead of f64 for checking valid number
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrxlz committed Feb 24, 2025
1 parent d07709c commit 109c25d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/kos-mobile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ serde = { workspace = true, features = ["derive"], optional = true }
num-bigint = "0.4"
num-traits = "0.2"
num-rational = "0.4.2"
regex = "1.11.1"
num-integer = "0.1.46"
bigdecimal = "0.4.7"

[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
uniffi = { workspace = true, features = ["build"] }
3 changes: 2 additions & 1 deletion packages/kos-mobile/src/number.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::KOSError;
use bigdecimal::BigDecimal;
use num_bigint::BigInt;
use num_integer::Integer;
use num_rational::BigRational;
Expand Down Expand Up @@ -62,7 +63,7 @@ impl BigNumber {
}

// Parse the value to check if it's a valid number
let parsed_value = match value.parse::<f64>() {
let parsed_value = match BigDecimal::from_str(value) {
Ok(num) => num.to_string(), // Convert to string to avoid precision loss
Err(_) => return Err(KOSError::KOSNumber("Invalid number format".to_string())),
};
Expand Down

0 comments on commit 109c25d

Please sign in to comment.