Created with Raphaël 2.0.0

Saturday, April 25, 2020

How to format double as integer and not use scientific notation


Here's how to format double as integer and not use scientific notation. See last line in code example below.

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
// setprecision example
#include <iostream>     // std::cout, std::fixed
#include <iomanip>      // std::setprecision
#include <string>
int main () {
  double f =79324623498343.12323;
  std::cout << std::setprecision(5) << f << '\n';
  std::cout << std::setprecision(9) << f << '\n';
  std::cout << std::fixed;
  std::cout << std::setprecision(5) << f << '\n';
  std::cout << std::fixed << std::setprecision(0) << f << '\n';
  return 0;
}

No comments:

Post a Comment - All Comments are Mediated. SPAM, Link Building, fake profiles, and BS will not pass.