Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <cinttypes>
#include <cstdio>

#include <double-conversion/double-conversion.h>

namespace facebook::react {

#if RN_DEBUG_STRING_CONVERTIBLE
Expand Down Expand Up @@ -129,20 +127,20 @@ SharedDebugStringConvertibleList DebugStringConvertible::getDebugProps() const {
* `toString`-family implementation.
*/
std::string toString(const double& value) {
// Format taken from folly's toString
static double_conversion::DoubleToStringConverter conv(
0,
"Infinity",
"NaN",
'E',
-6, // detail::kConvMaxDecimalInShortestLow,
21, // detail::kConvMaxDecimalInShortestHigh,
6, // max leading padding zeros
1); // max trailing padding zeros
std::array<char, 256> buffer{};
double_conversion::StringBuilder builder(buffer.data(), buffer.size());
conv.ToShortest(value, &builder);
return builder.Finalize();
std::array<char, 64> buffer{};
std::snprintf(buffer.data(), buffer.size(), "%.4f", value);
std::string result(buffer.data());

// Strip anything that ends up being an integer after reducing precision
if (auto dotPos = result.find('.'); dotPos != std::string::npos) {
auto lastNonZero = result.find_last_not_of('0');
if (lastNonZero == dotPos) {
result.erase(dotPos);
} else {
result.erase(lastNonZero + 1);
}
}
return result;
}

std::string toString(const void* value) {
Expand Down
Loading