Hi
Please check below MQL4 programming first:
double USOilAskStart = MarketInfo("USOIL", MODE_BID);
double UKOilAskStart = MarketInfo("UKOIL", MODE_BID);
double PriceGapStart = UKOilAskStart - USOilAskStart;
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?
how to set precision for double in C++
-
- 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.
You can #include <limits> to get the maximum precision of a float or double.
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;
-
- 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;
<< 3.14159265358979
<< std::endl;
-
- Posts: 1
- Joined: Thu Jan 25, 2018 1:21 am
- Contact:
Re: how to set precision for double in C++
thanks for the post
-
- Posts: 2
- Joined: Tue Apr 26, 2016 5:11 am
- Contact:
Re: how to set precision for double in C++
Thanks for the information!
-
- 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!
-
- 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.
<< 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.
-
- Posts: 1
- Joined: Sun Mar 20, 2022 2:37 am
- Contact:
Re: how to set precision for double in C++
Thanks for helping us to your valuable information!
Investing has the best results when you learn from nature.
-
- Posts: 2
- Joined: Fri Feb 24, 2023 7:27 am
Re: how to set precision for double in C++
Hello! thank you for sharing this info!!
Return to “Programming lessons”
Who is online
Users browsing this forum: No registered users and 10 guests