Skip to content

Commit 64a1e3c

Browse files
committed
[fix][libexpr] Fix float/double cast to decimal issue.
1 parent 0cc3717 commit 64a1e3c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/expr/calc/casting.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,12 @@ DecimalP Cast(bool v) {
188188

189189
template <>
190190
DecimalP Cast(float v) {
191-
String const f2s = CastFloat(v);
192-
return DecimalP(*f2s.GetPtr());
191+
return DecimalP(v);
193192
}
194193

195194
template <>
196195
DecimalP Cast(double v) {
197-
String const d2s = CastDouble(v);
198-
return DecimalP(*d2s.GetPtr());
196+
return DecimalP(v);
199197
}
200198

201199
template <>

test/types/test_type_decimal.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ TEST(TestTypeDecimal, DecimalTest) {
385385
//Test -dec 0.
386386
ASSERT_EQ((-Decimal(std::string("0"))).toLong(), 0);
387387

388+
//Test decimal to double
389+
DecimalP dp = DecimalP((double)32.91);
390+
ASSERT_EQ(dp.GetPtr()->toString(), std::string("32.9099999999999965894"));
391+
388392
//DecimalP p = DecimalP((float)12.34);
389393
ASSERT_EQ(DecimalP((long)12).GetPtr()->toString(10,4), std::string("12.0000"));
390394
ASSERT_EQ(DecimalP((float)12.34).GetPtr()->toString(10,4), std::string("12.3400"));

0 commit comments

Comments
 (0)