Can not print more decimals of ft
source link: https://www.codesd.com/item/can-not-print-more-decimals-of-ft.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Can not print more decimals of ft
This question already has an answer here:
- How do I print a double value with full precision using cout? 10 answers
I have tried to use long double type in my program to print out more digits of pi. But it only shows 5 digits decimal.
Here is my code.
int main(int argc, char** argv) {
long double pi_18 = acos(static_cast<long double>(-1));
cout << "pi to 18:" << pi_18 << endl;
return 0;
}
and this is my output:
pi to 18: 3.14159
How can I fix this problem?
Like so:
#include <iomanip>
#include <iostream>
std::cout << std::setw(15) << pi_18 << std::endl;
The width modifier only affects the next formatting operation, so if you want to format multiple numbers, you have to repeat it before every one. Check out the full documentation of format specifiers.
Related Articles
5006: An ActionScript File Can not Have More than One Definition Visible Outside
SimpleJdbcCall can not call more than one procedure
Why printf () in C can not print two 64-bit values at the same time?
No header is sent but PHP says the header can not contain more than one header & rdquo;
Can not print checkboxes in pdf
I can not add more menus to custom wordpress menus
SQL Server does not print more than 8,000 data lengths
Mongodb remove fragments - Can not have more than one drainage fragment at a time
Can not Print a Variable in Swift Mode
Can not Print in Color VS2010 RC
Can not print a long and long double output
Why System.out.println can not print a string value (in my particular case)?
how to check that this user can not enter more than one decimal point or point in the html web page
Bypassing the fact that python can not create more than one constructor
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK