C++/result in decimal order
Expert: vijayan - 9/30/2009
Questionhi can u help me. i want answer in desimal digits. for example. i product two large numbers like (22222 * 33333 = )it answer me in exp form like that ( = 123456 e^123456123) . but i want answer in linear form like ( = 123456789... ) with out exp or power of 10. i want sample. or code in detail. please help me out.
AnswerYou can easily format your output so that fields align correctly, floating point numbers have the representation and precision that you need, your numbers justified the way you want and so on. To do this you have to set the appropriate format flags for the stream - by using the member functions or 'manipulators' provided in <iostream> and <iomanip>
Here is a brief example on formatting floating point numbers using manipulators:
#include <iostream>
#include <iomanip>
int main()
{
double number = 22222.0 * 33333.0 ;
std::cout << number << '\n' // 7.40726e+08
<< std::fixed << number << '\n' // 740725926.000000
<< std::setprecision(2) << number << '\n' // 740725926.00
<< std::setprecision(0) << number << '\n' // 740725926
<< std::showpoint << number << '\n' // 740725926.
<< std::noshowpoint << number << '\n' ; // 740725926
}
For more information and examples, see:
http://www.cplusplus.com/reference/iostream/manipulators/
http://web.cs.wpi.edu/~cs1005/common/floatformats.html
http://www.arachnoid.com/cpptutor/student3.html