Skip to content

Commit

Permalink
Merge branch 'master' of github.com:paupino/rust-decimal into version…
Browse files Browse the repository at this point in the history
…/1.15
  • Loading branch information
paupino committed Jul 28, 2021
2 parents fad2d4f + 67b50ad commit 5b1da93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/decimal.rs
Expand Up @@ -1848,7 +1848,7 @@ impl ToPrimitive for Decimal {
let frac_f64 = (frac_part as f64) / (precision as f64);
let value = sign * ((integral_part as f64) + frac_f64);
let round_to = 10f64.powi(self.scale() as i32);
Some(value * round_to / round_to)
Some((value * round_to).round() / round_to)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/decimal_tests.rs
Expand Up @@ -2457,6 +2457,9 @@ fn it_converts_to_f64() {
None, // Cannot be represented in an f64
),
("1.59283191", Some(1.59283191_f64)),
("2.2238", Some(2.2238_f64)),
("2.2238123", Some(2.2238123_f64)),
("22238", Some(22238_f64)),
];
for &(value, expected) in tests {
let value = Decimal::from_str(value).unwrap().to_f64();
Expand Down

0 comments on commit 5b1da93

Please sign in to comment.