How to avoid `std::to_string()` making a very small double number to 0?

  c++, c++14, double, floating-point, tostring

I have a requirement to store very small double numbers into a string format and then later reverse them. However, when I try to run std::to_string() on a small number like 4.7816457028269855e-143 then it simply makes it 0.

I referred Set precision of std::to_string when converting floating point values and its linked duplicate. But will setting the precision to a very large number solve this issue in all the platforms?

How to fix this issue?
Using any alternatives to to_string() is fine.

Source: Windows Questions C++

LEAVE A COMMENT