I have a SQL query that returns a column with the BigDecimal type but my domain model works with f64:
price: Price::new(record.price).unwrap(),
^^^^^^^^^^^^
rustc: mismatched types
expected `f64`, found struct `BigDecimal`
How can I convert BigDecimal type into f64?
I was able to fix this problem by following steps
cargo add bigdecimal)use bigdecimal::ToPrimitive; to the top of the file where I want to convert types..to_f64() method on my BigDecimal instanceuse bigdecimal::ToPrimitive;
...
price: Price::new(record.price.to_f64().unwrap()).unwrap()
...
The to_f64() method appeared on the BigDecimal type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With