NumToStr is the preferred way,
because a mathematical way (eg multiply by 10) can introduce inaccuracies when the number gets processed back and forth multiple times.
Thanks TJ, but I don't see how this might work since we don't know beforehand how many decimals a variable will have, so which parameter needs to be entered for NumToStr()?
If we'd use a high value, say 20, then we're pretty sure the whole number will gets printed. For example:
Code: Select all
Variables:
myVariable(0), mySecondVar(0),
decimalsOfVariable(0);
if (LastBarOnChart_s = True) then begin
once cleardebug;
myVariable = 123.456789123;
mySecondVar = 9.80900;
Print("My variable 1: ", NumToStr(myVariable, 20));
Print("My variable 2: ", NumToStr(mySecondVar, 20));
end;
Now if we want to determine the number of decimals by counting the numbers behind the dot, we'll need to "cut off" all zeroes (in which case the number of decimals of 'mySecondVar' is underestimated with two). And secondly, NumToStr() doesn't always give a clean output. Look for example at the print out from the variables:
Code: Select all
My variable 1: 123.45678912299999000000
My variable 2: 9.80899999999999930000
So I don't think this is a solution either.