Skip to content

Commit

Permalink
Fix issue reported in #230
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlaucsb committed May 26, 2024
1 parent 3a88c95 commit 25a4f7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions include/internal/csv_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace csv {
return std::to_string(value);
#else
// TODO: Figure out why the below code doesn't work on clang
std::string result;
std::string result = "";

T integral_part;
T fractional_part = std::abs(std::modf(value, &integral_part));
Expand All @@ -124,8 +124,7 @@ namespace csv {
if (value < 0) result = "-";

if (integral_part == 0) {

result = "0";
result += "0";
}
else {
for (int n_digits = num_digits(integral_part); n_digits > 0; n_digits --) {
Expand Down
6 changes: 6 additions & 0 deletions tests/test_write_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ TEST_CASE("Numeric Converter Tsts", "[test_convert_number]") {
set_decimal_places(5);
}

SECTION("Decimal Numbers x where -1 < x < 0") {
REQUIRE(csv::internals::to_string(-0.25) == "-0.25000");
REQUIRE(csv::internals::to_string(-0.625) == "-0.62500");
REQUIRE(csv::internals::to_string(-0.666) == "-0.66600");
}

SECTION("Numbers Close to 10^n - Regression") {
REQUIRE(csv::internals::to_string(10.0) == "10.0");
REQUIRE(csv::internals::to_string(100.0) == "100.0");
Expand Down

0 comments on commit 25a4f7a

Please sign in to comment.