Skip to content

Commit 25a4f7a

Browse files
committed
Fix issue reported in #230
1 parent 3a88c95 commit 25a4f7a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/internal/csv_writer.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace csv {
114114
return std::to_string(value);
115115
#else
116116
// TODO: Figure out why the below code doesn't work on clang
117-
std::string result;
117+
std::string result = "";
118118

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

126126
if (integral_part == 0) {
127-
128-
result = "0";
127+
result += "0";
129128
}
130129
else {
131130
for (int n_digits = num_digits(integral_part); n_digits > 0; n_digits --) {

tests/test_write_csv.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ TEST_CASE("Numeric Converter Tsts", "[test_convert_number]") {
3535
set_decimal_places(5);
3636
}
3737

38+
SECTION("Decimal Numbers x where -1 < x < 0") {
39+
REQUIRE(csv::internals::to_string(-0.25) == "-0.25000");
40+
REQUIRE(csv::internals::to_string(-0.625) == "-0.62500");
41+
REQUIRE(csv::internals::to_string(-0.666) == "-0.66600");
42+
}
43+
3844
SECTION("Numbers Close to 10^n - Regression") {
3945
REQUIRE(csv::internals::to_string(10.0) == "10.0");
4046
REQUIRE(csv::internals::to_string(100.0) == "100.0");

0 commit comments

Comments
 (0)