ccplusplus.com
Learn C, C++ Concepts
Friday, February 3, 2012
cout precision example c++
/************************************************************************* * File : cout-precision.cpp * Author : Saurabh Gupta * Desc : cout precision example c++ * Source : http://www.ccplusplus.com/p/c_15.html * Created : 11:17 PM Friday, February 03, 2012 * Note : When outputting floating point numbers, cout has a default * precision of 6 — that is, it assumes all variables are only * significant to 6 digits, and hence it will truncate anything * after that. *************************************************************************/ #include
using namespace std; int main() { float fValue; fValue = 1.222222222222222f; cout << fValue << endl; fValue = 111.22222222222222f; cout << fValue << endl; fValue = 111111.222222222222f; cout << fValue << endl; return 0; } /* * OUTPUT * [sgupta@rhel6x86 cpp]$ c++ cout-precision.cpp -o cout-precision [sgupta@rhel6x86 cpp]$ ./cout-precision 1.22222 111.222 111111 [sgupta@rhel6x86 cpp]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment