https://rentry.org/PPP2_p386

// Code derived from Stroustrup's PPP2 book
// § 11.2.4 Precision
//  -and beginning on p 386

#include <iomanip>
#include <iostream>

using namespace std;

int main()
{
  cout << 1234.56789 << '\t' << fixed << 1234.56789 << '\t' << scientific
       << 1234.56789 << '\n';
  cout << defaultfloat << setprecision(5) << 1234.56789 << '\t' << fixed
       << 1234.56789 << '\t' << scientific << 1234.56789 << '\n';
  cout << defaultfloat << setprecision(8) << 1234.56789 << '\t' << fixed
       << 1234.56789 << '\t' << scientific << 1234.56789 << '\n';
}

build & run:

g++ -std=c++20 -O2 -Wall -pedantic ./ch_11/main_p386.cpp && ./a.out

PrevUpNext

Edit
Pub: 09 Apr 2023 05:04 UTC
Edit: 03 May 2023 10:25 UTC
Views: 305