NumbersSeparator() function for Print big numbers - page 2

 
nicholishen:

Late to the party... Here is a template function that can handle whatever number you throw at it. [MQL4/5]

Nice! This passed all my unit tests right out of the box, including 2^53.

 
Anthony Garot:

Nice! This passed all my unit tests right out of the box, including 2^53.


Thanks for the compliment, I appreciate it. :)

 
nicholi shen:

Thanks for the compliment, I appreciate it. :)

Just found this. Works great, though, I got errors declairing the template. I just removed that part and always send doubles. Works amazing. Thanks!
 
nicholish en:

Late to the party... Here is a template function that can handle whatever number you throw at it. [MQL4/5]

Thanks a lot  nicholish, this code solves one simple but tedious problem!
 
ali.bayat #:

HI

I need help

I need the number that tt_tprofit shows to be separated by three digits

Please help me if possible


Help with stolen code?

 
ali.bayat #:
   string l_text_116 =

Ask the real owner of the source code to give it to you or have him fix it for you.

Decompiled code is stolen code. Either you are a thief, a fence, or the receiver of stolen (intellectual) property. Either way, we will not be an accomplice after the fact to that theft.

See also
          Terms of Use of MQL5.community #3.13
          How can I recognize a decompiled code ? - General - MQL5 programming forum - Page 2 #17 (2017)
          134317 - MQL4 programming forum (2011)

If you post decompiled code again, you will likely be banned.

Don't tell us you found it on the 'net: if someone stole your bank details and uploaded them on to the internet, is it OK for everyone to use them because “someone uploaded it, I don't know why I can't use that?”

 

I needed a simple thousands separator for positive double numbers. I tried a couple of the functions from the answers here, which did not compile (in MT5). So I asked Cloud 3.5 Sonnet to write me one. Here it is. I does compile and works as expected:

string format_double_number(double numb) {
    // Convert the number to string and split into integer and decimal parts
    string num_str = DoubleToString(numb, 2);
    string parts[];
    StringSplit(num_str, '.', parts);
    
    // Handle the integer part
    string int_part = parts[0];
    string formatted = "";
    int len = StringLen(int_part);
    
    // Add digits with commas
    for(int i = 0; i < len; i++) {
        if(i > 0 && (len - i) % 3 == 0) {
            formatted += ",";
        }
        formatted += StringSubstr(int_part, i, 1);
    }
    
    // Add decimal part if it exists
    if(ArraySize(parts) > 1) {
        formatted += "." + parts[1];
    }
    
    return formatted;
}

Please note that it assumes a lot:

  • assumes the number is positive
  • assumes the integer-fraction seperator is "."
  • assumes you want the thousands seperator chracter to be ","
  • assumes there will only be 2 decimal places
These assumptions were what I wanted. If yours are different, you'd need to change the code accordingly (or have AI change it for you.)
 
majid4466 #:

I needed a simple thousands separator for positive double numbers. I tried a couple of the functions from the answers here, which did not compile (in MT5). So I asked Cloud 3.5 Sonnet to write me one. Here it is. I does compile and works as expected:

Please note that it assumes a lot:

  • assumes the number is positive
  • assumes the integer-fraction seperator is "."
  • assumes you want the thousands seperator chracter to be ","
  • assumes there will only be 2 decimal places
These assumptions were what I wanted. If yours are different, you'd need to change the code accordingly (or have AI change it for you.)
// Formats double with thousands separator and specified decimals.
string FormatDouble(const double number, const int digits, const string separator=",");

https://www.mql5.com/en/code/20822

Math Utils
Math Utils
  • www.mql5.com
Handy functions for comparison, rounding, formatting and debugging of doubles (prices, lots and money).