## how to set precision for double in C++

Examples step by step how to make your own automated strategy or user indicator
Message
Author
Ktanger
Posts: 1
Joined: Mon Apr 18, 2016 2:15 pm

### how to set precision for double in C++

Hi
Please check below MQL4 programming first:

if (NormalizeDouble(PriceGapStart, 3) >= 1.500)
{
...
}
the question is:
I want to find solution in C++ to set precision for double data like MQL4 above "NormalizeDouble(PriceGapStart, 3)" so that i can compare the result, any one can help me?

violajsilver
Posts: 5
Joined: Mon May 09, 2016 11:42 pm

### Re: how to set precision for double in C++

You can set the precision directly on std::cout and used the std::fixed format specifier.

Code: Select all

`double d = 3.14159265358979;cout.precision(17);cout << "Pi: " << fixed << d << endl;`

You can #include <limits> to get the maximum precision of a float or double.

Code: Select all

`#include <limits>typedef std::numeric_limits< double > dbl;double d = 3.14159265358979;cout.precision(dbl::max_digits10);cout << "Pi: " << fixed << d << endl;`

mark1205
Posts: 1
Joined: Wed Aug 31, 2016 4:05 am

### Re: how to set precision for double in C++

std::cout << std::setprecision (std::numeric_limits<double>::digits10 + 1)
<< 3.14159265358979
<< std::endl;

Jamesstewart01
Posts: 1
Joined: Thu Jan 25, 2018 1:21 am
Contact:

### Re: how to set precision for double in C++

thanks for the post

zoraya
Posts: 2
Joined: Tue Apr 26, 2016 5:11 am
Contact:

### Re: how to set precision for double in C++

Thanks for the information!

4waytechnologies
Posts: 1
Joined: Tue Mar 31, 2020 6:32 am
Location: California
Contact:

### Re: how to set precision for double in C++

Thanks for the information!

GragMilligan
Posts: 1
Joined: Thu May 06, 2021 12:50 am
Location: https://www.a-writer.com/professional-c ... y-writers/
Contact:

### Re: how to set precision for double in C++

std::cout << std::setprecision (std::numeric_limits<double>::digits10 + 1)
<< 3.14159265358979
<< std::endl;

Its works really. Accepting you really wanted to research articles forming and other making works out, we recommend that you visit some great site, actually look at this. I'm an understudy, yet I oftentimes ask him for help since it saves time and gives me results.