Call us! 512-349-0334 or (877) INDUSOFT

Formatting a Value Display in InduSoft Web Studio

Did you know that you can format your value displays to show tag values in many different formats in InduSoft Web Studio HMI software?

Simply using the Format() function in the value display allows you to format the values in a number of ways. The function is used with the following options:

Format(strFlag,numValue,optStrDecimalMark,optStrThousandSep)

Where:

strFlag

A description of how the given numerical value should be formatted, according to the syntax %width.precisionFormat, where:

  • width is the minimum number of characters to be returned by the function. If the value to be returned is shorter than this, then it is padded with either blank spaces (” “) or zeroes (“0”); see “Examples” below. The value is not truncated even if the result is longer than the specified width. Applicable for formats d, x, X, o, b, f, e, E, g, G, s, c and h.
  • .precision is the number of decimal places for a floating-point number. Applicable for formats f, e, E, g and G.
  • Format is the specific format:
Format Description
d Decimal
x Hexadecimal (alphabetic characters in lowercase)
X Hexadecimal (alphabetic characters in uppercase)
o Octal
b Binary
f Floating-point
e Scientific notation (e in lowercase)
E Scientific notation (E in uppercase)
g Rounded, in scientific notation when applicable (e in lowercase)
G Rounded, in scientific notation when applicable (E in uppercase)
s String (i.e., no change in number)
c ASCII character (i.e., the numerical value is interpreted as an ASCII character code)
h Hour (hh:mm:ss)

Alternatively, the format can be set using the syntax ##. ###, where the numerical value is rounded to the specified number of decimal places.

numValue

The numerical value to be formatted.

OptStrDecimalMark

The character used as the decimal mark, which separates the integer and fractional parts of the numerical value.

This is an optional parameter; if no value is specified, then the default is a period (.). For example: “123.45”

OptStrThousandSep

The character used as the thousands separator, which separates the hundreds and thousands digits of the numerical value.

This is an optional parameter; if no value is specified, then the default is a comma (,). For example: “12,345”

 

For instance, here are some examples:

Expression

Returned value

Format(“%d”,12.34) 12
Format(“%04d”,12.34) 0012
Format(“%4d”,12.34)   12

Expression

Returned value

Format(“%x”,26) 1a
Format(“%04x”,26) 001a
Format(“%4x”,26)   1a

 

Expression

Returned value

Format(“%X”,26) 1A
Format(“%04X”,26) 001A
Format(“%4X”,26)   1A

Expression

Returned value

Format(“%o”,16) 20
Format(“%04o”,16) 0020
Format(“%4o”,16)   20

 

Expression

Returned value

Format(“%b”,2) 10
Format(“%4b”,2) 0010
Format(“%04b”,2) 0010

Expression

Returned value

Format(“%0.1f”,12.34) 12.3
Format(“%06.1f”,12.34) 0012.3
Format(“%6.1f”,12.34)   12.3

 

Expression

Returned value

Format(“%e”,12.34) 1.234000e+001
Format(“%0.1e”,12.34) 1.2e+001
Format(“%09.1e”,12.34) 01.2e+001
Format(“%9.1e”,12.34)  1.2e+001

Expression

Returned value

Format(“%E”,12.34) 1.234000E+001
Format(“%0.1E”,12.34) 1.2E+001
Format(“%09.1E”,12.34) 01.2E+001
Format(“%9.1E”,12.34)  1.2E+001

 

Expression

Returned value

Format(“%0.1g”,12.34) 1e+001
Format(“%0.2g”,12.34) 12
Format(“%0.3g”,12.34) 12.3
Format(“%05.3g”,12.34) 012.3
Format(“%5.3g”,12.34)  12.3

Expression

Returned value

Format(“%0.1G”,12.34) 1E+001
Format(“%0.2G”,12.34) 12
Format(“%0.3G”,12.34) 12.3
Format(“%05.3G”,12.34) 012.3
Format(“%5.3G”,12.34)  12.3

 

Expression

Returned value

Format(“%s”,12.34) 12
Format(“%04s”,12.34) 0012
Format(“%4s”,12.34)   12

Expression

Returned value

Format(“%c”,97) a
Format(“%4c”,97)    a
Format(“%04c”,97) 000a

 

Expression

Returned value

Format(“%h”,30) 00:00:30
Format(“%h”,60) 00:01:00
Format(“%h”,90) 00:01:30
Format(“%h”,3600) 01:00:00

Expression

Returned value

Format(“##.#”,26.56789) 26.6
Format(“#.##”,26.56789) 26.57
Format(“##.##”,26.56789) 26.57

 

Comments are closed.