Skip to content

Commit

Permalink
number-to-string fix
Browse files Browse the repository at this point in the history
  • Loading branch information
saintmatthieu committed Feb 7, 2025
1 parent 4ece464 commit 26968c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/framework/global/tests/string_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,15 @@ TEST_F(Global_Types_StringTests, String_Number)
//! CHECK
EXPECT_EQ(str, u"2.12");
}

{
//! GIVEN Some double
double v = -0.01;
//! DO
String str = String::number(v, 1);
//! CHECK
EXPECT_EQ(str, u"0");
}
}

TEST_F(Global_Types_StringTests, String_ToInt)
Expand Down
7 changes: 6 additions & 1 deletion src/framework/global/types/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,12 @@ String String::number(double n, int prec)
--correctedIdx;
}

return fromAscii(s.c_str(), correctedIdx + 1);
const String result = fromAscii(s.c_str(), correctedIdx + 1);
if (result == "-0") {
return String(u"0");
} else {
return result;
}
}

float String::toFloat(bool* ok) const
Expand Down

0 comments on commit 26968c4

Please sign in to comment.