mercredi 28 septembre 2016

C++ setprecision only cuts off the digits.. it does not round

double d = 8.19999999999999999999;  
cout << d  << "\n";
cout << fixed << d  << "\n";
cout << setprecision(15) << d  << "\n";
cout << fixed << setprecision(15) << d  << "\n";

output

8.2
8.200000
8.199999999999999
8.199999999999999

Can I change that so it prints

 8.2
 8.200000
 8.200000000000000
 8.200000000000000

instead?

Aucun commentaire:

Enregistrer un commentaire