Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Edge HMI

Format

  • Last UpdatedAug 14, 2026
  • 4 minute read

Format formats a numeric value and returns it as a string.

Group

Sync / Async Exec

String Exp?

Windows Support

Windows Embedded Support

IoT View Support

Thin Client Support

Mobile Access Support

Arithmetic

Sync

Yes

Yes

Yes

Yes (see notes)

Yes

Yes

Syntax

Format(strFlag, numValue, optStrDecimalMark, optStrThousandSep)

strFlag

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

length is the minimum number of characters to be returned by the function — that is, the minimum length of the resulting string. If the value to be returned is shorter than this, it is padded with either blank spaces (" ") or zeroes ("0"); see the examples below. The value is not truncated even if the result is longer than the specified length. Applicable for Format values 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 Format values f, e, E, g, and G.

Format is the specific format:

Value

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 (no change in number)

c

ASCII character (the numeric value is interpreted as an ASCII character code)

h

Hour (hh:mm:ss)

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

numValue

The numeric value argument on which the function operation will be performed.

optStrDecimalMark

The character used as the decimal mark, which separates the integer and fractional parts of the numeric value. This is an optional parameter; 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 numeric value. This is an optional parameter; the default character is a comma (,).

Return value

This function returns a string that contains the formatted numeric value. See the examples below.

Notes

Format is similar to the printf function in other programming languages, and it allows most of the same formatting options. However, unlike printf, Format can be used to format only one numeric value at a time.

This function is particularly useful for formatting values to be printed in reports.

When you use this function to format a numeric value using scientific notation (when you specify e, E, g, or G for the Format part of strFlag), the return value will be somewhat different depending on the runtime edition of the project.

  • If project is run on Windows or Windows Embedded, the return value will show three characters for the exponent (for example, 1.2e+001).

  • If the project is run on IoT View, the return value will show only two characters for the exponent (for example, 1.2e+01).

This behavior is determined by the operating system and cannot be changed anywhere in the project. The actual numeric values are the same, but the difference in the number of characters means the resulting strings are different, especially if you also use the length part of strFlag to determine the minimum length of the strings. Also, because the resulting strings are different, they might be handled differently by other functions that are subsequently executed.

Examples

Expression

Return Value

Format("%d", 12.34)

12

Format("%04d", 12.34)

0012

Format("%4d", 12.34)

12

Format("%x", 26)

1a

Format("%04x", 26)

001a

Format("%4x", 26)

1a

Format("%X", 26)

1A

Format("%04X", 26)

001A

Format("%4X", 26)

1A

Format("%o", 16)

20

Format("%04o", 16)

0020

Format("%4o", 16)

20

Format("%b", 2)

10

Format("%4b", 2)

0010

Format("%04b", 2)

0010

Format("%0.1f", 12.34)

12.3

Format("%06.1f", 12.34)

0012.3

Format("%6.1f", 12.34)

12.3

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

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

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

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

Format("%s", 12.34)

12

Format("%04s", 12.34)

0012

Format("%4s", 12.34)

12

Format("%c", 97)

a

Format("%4c", 97)

a

Format("%04c", 97)

000a

Format("%h", 30)

00:00:30

Format("%h", 60)

00:01:00

Format("%h", 90)

00:01:30

Format("%h", 3600)

01:00:00

Format("##.#", 26.56789)

26.6

Format("#.##", 26.56789)

26.57

Format("##.##",26.56789)

26.57

Note: The examples above of scientific notation (e, E, g, G) are valid only for projects running on Windows and Windows Embedded. Projects running on IoT View will return values with only two characters for the exponent. For more information, see Notes above.

In This Topic