fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Number separator using commas

    Questions & Answers
    2
    3
    436
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Mantadiver last edited by

      I've searched the forum but unable to see a way to format numbers using commas as separators when adding to comments on screen.

      For example 34567 would display as 34,567

      Does anyone know if there is a built in function to achieve this or have a code snippet for such a function.

      Any help appreciated,

      Thank you

      l'andorrà 1 Reply Last reply Reply Quote 0
      • l'andorrà
        l'andorrà @Mantadiver last edited by

        @mantadiver The only way I know of is dividing the number by 1,000 before showing it on screen.

        (English) I will try to help everyone in these fxDreema forums. But if you want to learn how to use the platform in depth or more quickly, I can help you with my introductory fxDreema course in English at https://www.theandorraninvestor.eu.

        (Català) Miraré d’ajudar tothom en aquests fòrums d’fxDreema. Tanmateix, si vols aprendre a fer servir la plataforma amb més profunditat o més de pressa, t’hi puc ajudar amb el meu curs d’introducció a fxDeema en català a https://www.theandorraninvestor.eu/ca.

        (Español) Intentaré ayudar a todo el mundo en estos foros de fxDreema. Sin embargo, si quieres aprender a usar la plataforma en profundidad o más deprisa, te puedo ayudar con mi curso de introducción a fxDreema en español en https://www.theandorraninvestor.eu/es.

        1 Reply Last reply Reply Quote 0
        • M
          Mantadiver last edited by

          Managed to incorporate the "NumberToString" function put forward by nicholish en at end of page one of this mql5 forum thread 135250 (Google: NumbersSeparator() function for Print big numbers).

          This allows numbers to be automatically formatted with commas by using a new function:
          NumberToString ( numbertoconvert , decimalplaces )

          1. Create Custom Block
          2. Enter "NumberToString" as new block title in "new block..." field
          3. Look for pane "Global variables, includes" at bottom of page
          4. Type in "#include<Strings\String.mqh>"
          5. Look for pane in bottom right titled "Custom Functions" press "new"
          6. Remove the default text
          7. Paste in the code supplied by nicholish en:

          //+------------------------------------------------------------------+
          #include<Strings\String.mqh>
          template<typename T>
          string NumberToString(T number,int digits = 0,string sep=",")
          {
          CString num_str;
          string prepend = number<0?"-":"";
          number=number<0?-number:number;
          int decimal_index = -1;
          if(typename(number)=="double" || typename(number)=="float")
          {
          num_str.Assign(DoubleToString((double)number,digits));
          decimal_index = num_str.Find(0,".");
          }
          else
          num_str.Assign(string(number));
          int len = (int)num_str.Len();
          decimal_index = decimal_index > 0 ? decimal_index : len;
          int res = len - (len - decimal_index);
          for(int i = res-3;i>0;i-=3)
          num_str.Insert(i,sep);
          return prepend+num_str.Str();
          }
          //+------------------------------------------------------------------+

          1. Press "save" & close window
          2. Press "save changes" at top of custom blocks screen
          3. Return to fxdreema builder, refresh browser window and add new custom block in Oninit

          Then whenever number formats using commas are required use:-

          NumberToString ( numbertoconvert , decimalplaces )

          Output will show as 1,234,567 rather than 1234567.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post

          Online Users

          N
          S
          T
          A
          Y

          12
          Online

          146.7k
          Users

          22.4k
          Topics

          122.6k
          Posts

          Powered by NodeBB Forums | Contributors