Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ios_base::precision

      From cppreference.com
      <cpp‎ |io‎ |ios base
       
       
       
       
      streamsize precision()const;
      (1)
      streamsize precision( streamsize new_precision);
      (2)

      Manages the precision (i.e. how many digits are generated) of floating point output performed bystd::num_put::do_put.

      1) Returns the current precision.
      2) Sets the precision to the given one. Returns the previous precision.

      The default precision, as established bystd::basic_ios::init, is 6.

      Contents

      [edit]Parameters

      new_precision - new precision setting

      [edit]Return value

      The precision before the call to the function

      [edit]Example

      Run this code
      #include <iostream> int main(){constdouble d=12.345678901234;std::cout<<"The  default precision is "<<std::cout.precision()<<"\n\n";std::cout<<"With default precision d is "<< d<<'\n';std::cout.precision(8);std::cout<<"With high    precision d is "<< d<<'\n';}

      Output:

      The  default precision is 6 With default precision d is 12.3457With high    precision d is 12.345679

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 189C++98'precision' was defined as 'the number of digits after
      the decimal point', but it is not correct in some cases
      corrected

      [edit]See also

      manages field width
      (public member function)[edit]
      changes floating-point precision
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/ios_base/precision&oldid=159331"

      [8]ページ先頭

      ©2009-2025 Movatter.jp