how to convert the minimum double value in fixed format to string
|
2 answers
double d = std::numeric_limits<double>::min(); std::string s; int j = 0, count = 0; while(!j) { d *= 10; j = d; s += '0'; ++count; } --count; // нулей после точки s[0] = '.'; std::ostringstream os; os << d; std::string b = os.str(); b.erase(b.find('.'),1); s += b; std::cout << s; // ваш ответ Usually the exponential form (scientific format) is better. It can be displayed immediately:
#include <iomanip> //... std::cout << std::scientific << std::numeric_limits<double>::min(); - And why is the answer to the point empty? - Stanislav Petrov
- @Stanislav Petrov: if you write double r = .1; the compiler will understand it as 0.1, but if you want to display 0 before the point, it’s not difficult to add a character to the beginning of the line ... - AR Hovsepyan
|
Answer:
#include <iostream> #include <sstream> int main() {double number = 0.10; stringstream bla; string str; bla << number; str = bla.str(); } - the
std::stringstreamis called<sstream>- Fat-Zer - Yes, and 0.10 is far from
std::numeric_limits<double>::min(). - Ternvein
|