Displays float as -2.13323e + 007. How to make normal output - the usual fraction through cout?

  • In general, it is strange that it displays with the exponent, usually the numbers that do not fit are discarded ... maybe it depends on the compiler, I use visual studio and have not encountered this. - Comfmore
  • that is, you need a type of numerator by denominator?!? - rojaster

4 answers 4

Like this:

std::cout << std::fixed << 221414252135125453453245325234.0 << std::endl; 
     float f = что-нибуть; char str[32]; sprintf(str, " %3.10f ", f); cout << str << endl; 

    Ugly, but no need to think :)

    • * Printf always seemed to me more convenient than cout :-) Aside from the nuance that cout makes it easier to output entire classes (overload / friendship). - gecube

    If the memory fails, the variable lacks a range of values. Use the long qualifier.

      Try this:

       #include <iostream> using namespace std; int main() { float d; cout<<"Введите вещественное число: "; cin>>d; cout.setf(ios_base::fixed); //задаёт формат вывода cout<<d; return(0); } 

      Here, read on this topic: http://savardge.narod.ru/cpp/article_cpp_t9.html