std::setprecision
提供: cppreference.com
| ヘッダ <iomanip> で定義
|
||
| /*unspecified*/ setprecision( int n ); |
||
式 out << setprecision(n) または in >> setprecision(n) で使用されたとき、ストリーム out または in の precision パラメータをちょうど n に設定します。
目次 |
[編集] 引数
| n | - | 精度の新しい値 |
[編集] 戻り値
str が std::basic_ostream<CharT, Traits> 型の出力ストリームまたは std::basic_istream<CharT, Traits> 型の入力ストリームの名前である場合に式 str << setprecision(n) または str >> setprecision(n) が以下のコードが実行されたかのように動作するような、未規定な型のオブジェクトを返します。
str.precision(n);
[編集] 例
Run this code
#include <iostream> #include <iomanip> #include <cmath> #include <limits> int main() { const long double pi = std::acos(-1.L); std::cout << "default precision (6): " << pi << '\n' << "std::setprecision(10): " << std::setprecision(10) << pi << '\n' << "max precision: " << std::setprecision(std::numeric_limits<long double>::digits10 + 1) << pi << '\n'; }
出力:
default precision (6): 3.14159 std::setprecision(10): 3.141592654 max precision: 3.141592653589793239
[編集] 関連項目
| (C++11)(C++11) |
浮動小数点の入出力に使用される書式を変更します (関数) |
| 浮動小数点操作の10進精度を管理します ( std::ios_baseのパブリックメンバ関数)
|

