Lesson 3 - MQL4 Data types

 
Files:
lesson3.pdf  98 kb
 

An other question.

double should be between 2.2e-308 to 1.8e308.

What is e?

Is it in hexadecimal format?

And an other question.

I know that somebody uses the letters before name of variables, for example:

int nSomeNumber = 12345;

bool bIsRightPlace = true;

double fCurrentPrice = 1.2344;

datetime tCurrentDate = D'2005.02.02. 8;00';

color cChartColor = Olive;

string sMyName = "Joel"

I mean n for int, b for bool, f for double, t for datatime, c for color and s for string. Is it still usable?

 

Exponential notation & Hungarian notation.

newdigital:
An other question.

double should be between 2.2e-308 to 1.8e308.

What is e?

Is it in hexadecimal format?

And an other question.

I know that somebody uses the letters before name of variables, for example:

int nSomeNumber = 12345;

bool bIsRightPlace = true;

double fCurrentPrice = 1.2344;

datetime tCurrentDate = D'2005.02.02. 8;00';

color cChartColor = Olive;

string sMyName = "Joel"

I mean n for int, b for bool, f for double, t for datatime, c for color and s for string. Is it still usable?

Thank you newdigital for your intelligent questions.

Question 1:

2.2e-308 and1.8e308 are numbers wrote in exponential notation.

Exponential notation is a way of writing large numbers without having to write out a lot of zeros, for example, 1,000,000,000 can be written as 1.0E9.

The number followed the E is called the exponent and it indicates how many places the decimal point must be moved to change the number to the normal decimal notation.

The exponent can be positive or negative; the exponential number 6.35E-5 is equivalent to 0.0000635 in decimal notation.

Question 2:

Yes, this is very a good programming practice, and it called Hungarian notation.

Hungarian notation is a naming convention in programming, in which the name of a variable (or function) indicates its type or intended use.

You prefixed every variable name with the first letter of the variable type, and that's what Hungarian notation mean.

 

You described that we should write a null character after the last character of data in data type string.

But it was nothing in the examples:

string str1 = "Hello";

So no null.

May be it was for the explanation only?

 

Null-terminated strings

newdigital:
You described that we should write a null character after the last character of data in data type string.

But it was nothing in the examples:

string str1 = "Hello";

So no null.

May be it was for the explanation only?

Hi newdigital,

Thank you very much for your question, it's an intelligent one.

This kind of strings (and it's the only kind MQL4 uses) called Null-terminated strings

The NULL has putted for you automatically when you used the "string" keyword to create a string type variable.

So you must not add NULLto the end of your string, because MQL4 will add it automatically.

string str1 = "Hello"; will be presented in the memory like that:

H e l l o NULL

 

May exponential notation be used in the code?

for example:

double fCoefficient = 2.5E-4

 

Exponential notation can't be used in MQL4.

newdigital:
May exponential notation be used in the code?

for example:

double fCoefficient = 2.5E-4

newdigital,

Your questions enrich the course. Thanks!

I've used the exponential notation in my lesson to tell you what the range of float data type is (2.2e-308 to 1.8e308), because I can't write these numbers in decimal notation.

Do you imagine 307 zeros in the right of the number 18 to present the number 1.8e308.

In MQL4, you can't use the exponential notation.

To present the number 2.5E-4 in MQL4 you have to write it in decimal notation like this:

double fCoefficient = 0.00025;

 

mike

Hi, I've found lessons 1 and 2 so no need to reply to my message about not being able to find them.

regards

mike

 
mike:
Hi, I've found lessons 1 and 2 so no need to reply to my message about not being able to find them.

regards

mike

Hi mike,

Welcome to my lessons, I hope you enjoy them.

 
codersguru:
...

Question 1:

2.2e-308 and1.8e308 are numbers wrote in exponential notation.

Exponential notation is a way of writing large numbers without having to write out a lot of zeros, for example, 1,000,000,000 can be written as 1.0E9.

The number followed the E is called the exponent and it indicates how many places the decimal point must be moved to change the number to the normal decimal notation.

The exponent can be positive or negative; the exponential number 6.35E-5 is equivalent to 0.0000635 in decimal notation....

Hmmm, so I think 2.2e-308 = 2.2 x 10 to the power of -308, and 1.8e308 = 1.8 x 10 to the power of 308.

 
mcintyd1:
Hmmm, so I think 2.2e-308 = 2.2 x 10 to the power of -308, and 1.8e308 = 1.8 x 10 to the power of 308.

That's right!

Reason: