LoginSignup
4
3

More than 5 years have passed since last update.

【競プロメモ】標準出力に桁数指定でdoubleを出す方法

Posted at

C++のdouble出力は標準が6桁になっているらしく、精度が足りなくてWAになることがあったのでメモ

小数点以下の桁数を指定する方法

#include <iomanip>
// 小数点以下の桁数を指定できるように
cout << fixed;
// setprecisionで小数点以下8桁を出すように
cout << setprecision(8) << result << endl;

fixedにしないと、小数点より上含めて全部で8桁出力になってしまうので注意。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3