How Normalize() is calculated?

 
Does anybody know how Normalize() or NormalizeDouble() is calculated? I want to know the internal calculation of this function.

How to rewrite the Normalize() function in C ?

Thanks in advance
 
Try something like:

// get a one with digit zeros behind/ 10, 100, 1000
double f= 1;
for (int i= 0; i<digits; i++) {
f*= 10;
}

// round it up
double result= (int)(roundwhat*p + 0.5);
result/= p;



Markus
 
Shimodax, your calculation is incorrect. The result of your calculation and result of the original Normalize() is different.

But thank you anyway.
 
Hi!

I just hacked it up here in the message window (just saw that "p" shoudl be "f"). But I think it will be something like that.

However, I just tried this and it gave the same result as NormalizeDouble(d, 4); => Result 1.2346

	double roundwhat= 1.234567;
	int digits= 4;
	// get a one with digit zeros behind/ 10, 100, 1000
	double f= 1;
	for (int i= 0; i<digits; i++) {
	   f*= 10;
	}

	// round it up
	double result= (int)(roundwhat*f + 0.5);
	result/= f;
 
Your algoritm always round up while NormalizeDouble() sometimes round down and up. I've compared a wide range of values and found that yours and MetaTrader's vary about 70%.
 
Oh, nevermind ... it was worth a try :-)


Markus
 
I need to know this urgently too. How to rewrite NormalizeDouble() in C/C++? Maybe this function is somehow flawed that's why it rounds numbers randomly?
Reason: