How to avoid all the Zeros when Printing a double variable?

 
If I use Print() or shows the value on screen with object_create, my double variables shows all the zeros for a certain length.

Ex value 1.235
is shown as 1.23500000000

Is there any way to "hide" all theese zeros? I've tried using NormalizeDouble(), but this only decides how many numbers behind the comma.

Thanks in advance,
Johan
 
 
Thank you for your answe phy.

But, using this I can only limit the number of characters after the comma. I want:

1.235235000000000000 to be 1.235235
and 1.1000000000000 to be 1.1

Is there a simple way?
 
.
 
//+------------------------------------------------------------------+
//| Function..: Decimals                                             |
//| Parameters: xValue - boolean/double/integer/string value.        |
//| Purpose...: Determine the number of digits after the decimal     |
//|             point in a double value, for formatting a number.    |
//| Returns...: iDecimal - decimal places.                           |
//| Notes.....: The function is precise if the number of decimals    |
//|             does not exceed 8.                                   |
//| Example...: double dVal=1.12345678;                              |
//|             Print("dVal=",DoubleToStr(dVal,Decimals(dVal)));     |
//|             dVal=1.1;                                            |
//|             Print("dVal=",DoubleToStr(dVal,Decimals(dVal)));     |
//+------------------------------------------------------------------+
int Decimals(string sVal) {
  int iPos=StringFind(sVal,".");
  if(iPos==-1) return(0);
  int iLen=StringLen(sVal), iCnt=0;
  for(int i=iLen-1; i>=iPos; i--) {
    if(StringGetChar(sVal,i)==48) iCnt++;
    else break;
  }
  return(iLen-iCnt-iPos-1);
}
 
Hi Flirrrt,

Maybe using StringConcatenate().

double dTemp=1.22000;
Comment("test x " +  dTemp + " | " + StringConcatenate("test y ",dTemp));
Print("test x" +  dTemp);
Print(StringConcatenate("test y ",dTemp));



In the above case all zeros are removed? Perhaps this will work...?

Regards,
pipthis

 
pipthis, a little gem, well done.
Reason: