Skip to content

Commit

Permalink
Support comma separated thousands in monetary amount
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Dec 5, 2024
1 parent a47f170 commit 2985b9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/basic-objects/src/monetaryamount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ inline std::pair<MonetaryAmount::AmountType, int8_t> AmountIntegralFromStr(std::
if (ch == ' ') {
break;
}
if (ch == ',') {
// Comma can be used to separate thousands, we ignore it.
continue;
}
throw exception("Amount string {} with invalid character {}", amountStr, ch);
}

Expand Down
2 changes: 2 additions & 0 deletions src/basic-objects/test/monetaryamount_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ TEST(MonetaryAmountTest, ExoticInput) {

EXPECT_EQ(MonetaryAmount(" -.9 f&g "), MonetaryAmount("-0.9F&G"));

EXPECT_EQ(MonetaryAmount("2,708.89034514"), MonetaryAmount("2708.89034514"));

EXPECT_THROW(MonetaryAmount("--.9"), exception);
}

Expand Down

0 comments on commit 2985b9b

Please sign in to comment.