Display a REAL variable with thousands separator and its unit (Plant SCADA 2020 R2 8.30)

Hi all,

I have a REAL variable with units (here l), and I want to display it with a space as thousands separator, and of course keeping its unit.

The variable have the following parameters :

For example, I have 1245687 comming from the PLC in this variable, and I want to display 1 245 687 l

Until now I haven't found out how to do it... and I have 1245687 l on my display, that is not nice, not easy to read.

Is there someone who can help me ?

Best regards,

Fred

Parents
  • Here's an example of a cicode function that you can call from a graphics page. It takes an integer value and returns it as a formatted string with thousands separators:

    STRING
    FUNCTION BigFormat(REAL rValue, STRING sSep=",")
    INT i;
    INT iDiv;
    INT iRem;
    STRING sValue;
    STRING sFormattedValue;

    sValue = StrTrim(RealToStr(rValue, 10, 0));
    iDiv = (StrLength(sValue)-1) / 3;
    iRem = ((StrLength(sValue)-1) MOD 3) + 1;

    sFormattedValue = StrLeft(sValue, iRem);

    FOR i = 0 TO iDiv - 1 DO
    sFormattedValue = sFormattedValue + sSep + StrMid(sValue, iRem + (i*3), 3);
    END

    RETURN sFormattedValue;
    END

     

    The default separator in this example is a comma, but you can override that if you specify it as the second argument. For your case you would call it like this from a graphics element:

    BigFormat(MyTag, " ")

  • There's a similar function in the Citect Toolbox:  Comma-Delimited Values 

    It is a little longer, but works with integers, floating-point numbers, positive, and negative values. However, you would have to edit one line of code to change the comma to a space:

    sOutput = "," + sOutput;

    I don't think I ever tested my code with variables having engineering units in the format (like ##########.### EU). Surprisingly, it seems to work since the function accepts the value as a STRING. When you pass a variable tag with EU in the format, and specify mode 1 (REAL number), it automatically gets converted to a string, like "123.45 RPM". However, if you use INT mode (0), it strips off the engineering units with the decimal places.

    I noticed that BigFormat() doesn't seem to work with negative numbers, and even though you pass a REAL to it, it rounds to the nearest whole number. Of course, if you only need to display accumulators or other large, positive integers, that wouldn't be an issue.

Reply
  • There's a similar function in the Citect Toolbox:  Comma-Delimited Values 

    It is a little longer, but works with integers, floating-point numbers, positive, and negative values. However, you would have to edit one line of code to change the comma to a space:

    sOutput = "," + sOutput;

    I don't think I ever tested my code with variables having engineering units in the format (like ##########.### EU). Surprisingly, it seems to work since the function accepts the value as a STRING. When you pass a variable tag with EU in the format, and specify mode 1 (REAL number), it automatically gets converted to a string, like "123.45 RPM". However, if you use INT mode (0), it strips off the engineering units with the decimal places.

    I noticed that BigFormat() doesn't seem to work with negative numbers, and even though you pass a REAL to it, it rounds to the nearest whole number. Of course, if you only need to display accumulators or other large, positive integers, that wouldn't be an issue.

Children