diff --git a/src/decimal.rs b/src/decimal.rs index e88dda43..944ddbc9 100644 --- a/src/decimal.rs +++ b/src/decimal.rs @@ -914,7 +914,7 @@ impl Decimal { // floating point number if is64 { // Guaranteed to about 16 dp - while exponent10 < 0 && (bits[2] != 0 || (bits[1] & 0xFFE0_0000) != 0) { + while exponent10 < 0 && (bits[2] != 0 || (bits[1] & 0xFFF0_0000) != 0) { let rem10 = div_by_u32(bits, 10); exponent10 += 1; if rem10 >= 5 { diff --git a/tests/decimal_tests.rs b/tests/decimal_tests.rs index 87b24fed..8e16e670 100644 --- a/tests/decimal_tests.rs +++ b/tests/decimal_tests.rs @@ -1142,6 +1142,9 @@ fn it_converts_from_f64() { from_f64(0.12345678901234567890123456789f64).unwrap().to_string() ); assert_eq!("0", from_f64(0.00000000000000000000000000001f64).unwrap().to_string()); + assert_eq!("0.6927", from_f64(0.6927f64).unwrap().to_string()); + assert_eq!("0.00006927", from_f64(0.00006927f64).unwrap().to_string()); + assert_eq!("0.000000006927", from_f64(0.000000006927f64).unwrap().to_string()); assert!(from_f64(std::f64::NAN).is_none()); assert!(from_f64(std::f64::INFINITY).is_none());