mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix exception when converting to decimal values that reduce to N/1.
Before this the loop wouldn't terminate until the denominator had been reduced to 0 and trying to create a GncRational with a 0 denominator throws.
This commit is contained in:
parent
d03dc07b8d
commit
2290fa7c22
@ -368,7 +368,7 @@ GncNumeric::to_decimal(unsigned int max_places) const
|
||||
rr_num *= factor;
|
||||
rr_den *= factor;
|
||||
}
|
||||
while (!rr_num.isZero() && rr_num % 10 == 0)
|
||||
while (!rr_num.isZero() && rr_num > 9 && rr_den > 9 && rr_num % 10 == 0)
|
||||
{
|
||||
rr_num /= 10;
|
||||
rr_den /= 10;
|
||||
|
@ -548,4 +548,16 @@ TEST(gnc_numeric_functions, test_conversion_to_decimal)
|
||||
EXPECT_NO_THROW(r = c.to_decimal());
|
||||
EXPECT_EQ(27434842, r.num());
|
||||
EXPECT_EQ(100, r.denom());
|
||||
GncNumeric d(11900000000, 85000000);
|
||||
EXPECT_NO_THROW(r = d.to_decimal());
|
||||
EXPECT_EQ(140, r.num());
|
||||
EXPECT_EQ(1, r.denom());
|
||||
GncNumeric e(11050000000, 65000000);
|
||||
EXPECT_NO_THROW(r = e.to_decimal());
|
||||
EXPECT_EQ(170, r.num());
|
||||
EXPECT_EQ(1, r.denom());
|
||||
GncNumeric f(5000000000, 50000000 );
|
||||
EXPECT_NO_THROW(r = f.to_decimal());
|
||||
EXPECT_EQ(100, r.num());
|
||||
EXPECT_EQ(1, r.denom());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user