Skip to content

Commit 0cc3717

Browse files
nokiaMSgithubgxll
authored andcommitted
[fix][libexpr] Fix decimal neg operation issue.
1 parent 7db16cf commit 0cc3717

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/types/decimal/decimal.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include <iostream>
16+
#include <sstream>
1617
#include "decimal.h"
1718

1819
namespace dingodb {
@@ -382,9 +383,9 @@ Decimal Decimal::operator-() const {
382383
result.append(str, curPos);
383384
}
384385
else {
385-
result.append(str, curPos, exp);
386-
result.push_back('.');
387-
result.append(str, curPos + exp);
386+
std::ostringstream oss;
387+
oss << 0 - v;
388+
result = oss.str();
388389
}
389390

390391
return std::move(Decimal(result));

test/types/test_type_decimal.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ TEST(TestTypeDecimal, DecimalTest) {
360360
//Test dec > dec.
361361
ASSERT_FALSE(Decimal(std::string("123.123")) > Decimal(std::string("123.124")));
362362

363+
//Test -dec.
364+
//This case will append '.00' in serial stage.
365+
ASSERT_EQ((-Decimal(std::string("10.00"))).toString(), std::string("-10"));
366+
363367
//Test -dec.
364368
ASSERT_EQ((-Decimal(std::string("123.123"))).toString(), std::string("-123.123"));
365369

0 commit comments

Comments
 (0)