Format Specifier Syntax
- Updated2026-09-28
- 11 minute(s) read
Understand LabVIEW format specifier syntax for format strings that format output or scan input.
Format Specifier Syntax for Formatting Functions
Formatting functions use full format specifier syntax:
%[$][-][+][#][^][0][Width][.Precision∥_Significant Digits][{Unit}][<Embedded Time Format>]Conversion Code
where
- Width must be a number greater than zero
- Precision or Significant Digits must be a number greater than or equal to zero
- Double brackets [] indicate optional elements. You do not need to include literal [] characters in the format specifier unless a specific syntax element requires them.
- ∥ indicates that, if you decide to use .Precision or _Significant Digits, you must choose one or the other.
- Replace text in the syntax with an appropriate syntax element.
Format Specifier Syntax for Scanning Functions
Scanning functions use a simplified format specifier syntax:
%[Width]Conversion Code
where Width must be a number greater than zero
- Double brackets [] indicate optional elements. You do not need to include literal [] characters in the format specifier.
- Replace text in the syntax with an appropriate syntax element.
Format Specifier Syntax Elements
Format specifiers support specific syntax elements that define how LabVIEW functions interpret input strings and produce an output string. Understand the format specifier syntax to use to create the output strings you need.
% Delimiter
Required element that begins a format specifier.
The Format Into String, Format Into File, Scan From String, and Scan From File functions are expandable. These functions can use multiple format specifiers in the format string, one for each input or output of the function.
- The number of format specifiers in the format string must match the number of arguments to the function.
- To specify multiple format specifiers in the format string input, indicate each format specifier with %.
Modifiers
Use optional modifier elements to refine the output that a format string creates.
| Syntax Element | Formatting Function or Scanning Function | Description |
|---|---|---|
| $ | Formatting | Specifies the order in which to display variables. Include the digit that represents the order of the variable immediately before this modifier. |
| - | Formatting | Left justifies the parameter within its width rather than right justifies it. |
| + | Formatting | Includes sign even when the number is positive. |
| ^ | Formatting |
|
| # | Formatting | Removes trailing zeros. If the number has no fractional part, this modifier also removes the description part. |
| 0 | Formatting | When used without the - modifier, pads any excess space to the left of a numeric parameter with zeros rather than with spaces to reach minimum width. |
| Width |
|
|
| .Precision or _Significant Digits | Formatting | Controls the number of digits displayed, where either
Precision or Significant
Digits is a number. Note You cannot use precision and significant digits
together in a single format specifier.
|
| {Unit} | Formatting | Overrides the original unit of a VI when you use a function to
convert a physical quantity (a value with an associated unit). You
must use a compatible unit. Note You can use
this syntax element only with the Format Into String
function. |
| <Embedded Time Format> | Formatting | Contains a time-specific format string for use with the T (absolute time) and t (relative time) conversion codes. For valid embedded time format strings, refer to Time-Specific Format Codes. |
Conversion Codes
Characters that specify how to scan or format a parameter. Required elements for both scanning functions and formatting functions.
Conversion codes operate primarily with a specific type of data but can interpret multiple types of data.
Conversion Codes for Numbers
| Conversion Code | Supported Numerics | Description |
|---|---|---|
| x |
|
Hexadecimal integer (for example, B8). |
| o |
|
Octal integer (for example, 701). |
| b |
|
Binary integer (for example, 1011). |
| d |
|
Signed decimal integer. |
| u |
|
Unsigned decimal integer. |
| f |
|
Floating-point number with fractional format (for example, 12.345). |
| e |
|
Floating-point number in scientific notation (for example, 1.234E1). |
| g |
|
Automatic formatting. Depending on the exponent of the number,
uses either f or e.
|
| p |
|
Floating-point number in SI notation. |
- Booleans: 0 represents False, 1 represents True
- Enums: Interprets the numeric index value of the enum item
Conversion Codes for Strings
| Conversion Code | Description |
|---|---|
| s | String (for example, abc)
|
| [ ] | Characters in set: matches a string that contains only the
characters specified between the brackets. Note The [ ] conversion code
is useful only when you are scanning strings, not formatting
strings. Character matches are case sensitive. The following characters have special meanings within the [ ] conversion code:
The following examples demonstrate the use of the characters in set conversion code:
|
- Booleans: Interprets False and True
- Enums: Interprets the string label of the enum item
- Named refnums, such as DAQmx channels or VISA resource names
- Paths
Conversion Codes for Time
| Conversion Code | Description |
|---|---|
| T | Absolute time. Use T in the Display
Format property of numeric or time stamp controls,
constants, and indicators, as well as the Format Into
String, Format Into File,
Scan From String, and Scan From
File functions. Note You cannot
use T with the Array To Spreadsheet
String, Spreadsheet String To
Array, Format Value, and
Scan Value functions. Formatting a time stamp as anything other than time returns an error. |
| t | Relative time. Use t in the Display
Format property of numeric or time stamp controls,
constants, and indicators, as well as the Format Into
String,Format Into File,
Scan From String, and Scan From
File functions. Note You cannot
use t with the Array To Spreadsheet
String, Spreadsheet String To
Array, Format Value, and
Scan Value functions. Formatting a time stamp as anything other than time returns an error. |
Localization Codes
Optional sequence that determines whether LabVIEW uses a decimal or comma to separate the whole number from the decimal part of the number.
These codes control the decimal separator for numeric output. These codes do not cause any input or output to occur. They change the decimal separator for all further inputs and outputs until they find the next %;.
| Localization Code | Description |
|---|---|
| %,; | Comma decimal separator. |
| %.; | Period decimal separator. |
| %; | System default separator. If you do not specify a separator, LabVIEW uses the system default separator. |
Literal Characters
If you want to add characters to an input string, you can add literal characters to the format string. You can use escape sequences in format strings to insert certain characters.
| Escape Sequence | Output | Description |
|---|---|---|
| %% | % | Avoid collision with the % delimiter that defines the beginning of a format specifier. |
| \> | > | Avoid collision with the > delimiter that ends the embedded time format modifier. |
| Backslash (\) codes | Depends on backslash code | Character sequence that specify hex values, spacing, backspaces,
and other formatting options. For more information about backslash codes, refer to Backslash ('\') Codes Display. |
Format Specifier Syntax Examples
Understand how LabVIEW format specifiers convert input arguments to output strings with practical examples.
Automatic Formatting (%g) Example
| Argument | Format String | Resulting String |
|---|---|---|
| 12.00 | %#g | 12 |
| 12000000 | %#g | 1.2E+7 |
If you specify #, LabVIEW removes trailing zeros.
If you specify g, LabVIEW chooses scientific notation or floating-point notation based on the exponent of the number to format.
Decimal (%d) Example
| Argument | Format String | Resulting String |
|---|---|---|
| 12.67 | score= %d%% | score= 13% |
When you specify %d, LabVIEW displays integers in base-10 decimal format.
- For signed or unsigned integers of any bit size, LabVIEW displays the integer unmodified.
- LabVIEW rounds floating-point values to signed 64-bit integers. NaN and values greater than the maximum value of a signed 64-bit integer are rounded to the maximum value of a signed 64-bit integer, which is 9223372036854775807. To record values greater than the maximum value of a signed 64-bit integer, you must explicitly cast the values to unsigned 64-bit integers using the To Unsigned Quad Integer function.
Floating-Point (%f) Example
| Argument | Format String | Resulting String |
|---|---|---|
| 12.67 | Temp: %5.1f | Temp: 12.7 |
| 12.67 N | %5.3f | 12.670 N |
| 12.67 N | %5.3{mN}f | 12670.000 mN |
| 12.67 N | %5.3{kg}f | 12.670 ?kg |
- 5 in the format string specifies a width of 5. The number after . specifies the number of digits to the right of the decimal, or precision.
- Units are valid only if you use the Format Into
String function. The examples with a unit show how
format specifiers interact with physical quantities.
- You can convert from one unit to another.
- The question mark indicates when the unit in the format specifier is in conflict with the input unit.
Scientific Notation (%e) Example
| Argument | Format String | Resulting String |
|---|---|---|
| 12.67 | %.3e | 1.267E+1 |
| 12.67 | %^.3e | 1.2670E+0 |
You can add ^ to change to engineering notation, where the exponent is always a multiple of three.
SI Notation (%p) Example
| Argument | Format String | Resulting String |
|---|---|---|
| 12000000 | %.2p | 12.00M |
| 12000000 | %_2p | 12M |
- A value of .2 specifies that you want a precision of two digits in the resulting string.
- A value of _2 specifies that you want two significant digits in the resulting string.
- The %p code adds the SI prefixes.
Hexadecimal (%x), Octal (%o), and Binary (%b) Example
| Argument | Format String | Resulting String |
|---|---|---|
| 12 | %02x | 0C |
| 12 | %06o | 000014 |
| 12 | %b | 1100 |
b (binary) is base 2. o (octal) is base 8. x (hexadecimal) is base 16.
- You can use the - modifier to left justify the resulting string.
- The 0 modifier indicates to pad the resulting string with zeroes.
- The digit in the format specifier specifies the width of the resulting string.
For example, a modifier -n pads the resulting string with spaces to the n width.
Relative Time (%t) Example
| Argument | Format String | Resulting String |
|---|---|---|
| 91.80 | %.2t | 01:31.80 |
| 91.8 | %<Hours:%H Minutes:%M Seconds:%S>t | Hours:00 Minutes:01 Seconds:31 |
LabVIEW formats elapsed time in terms of the following:
- Complete weeks (%W)
- Complete days (%D)
- Complete hours (%H)
- Complete minutes (%M)
- Complete seconds (%S)
- Fractions of seconds (%digitu)
For more information on the embedded time format codes, refer to Time-Specific Format Codes.
Absolute Time (%T) Example
| Argument | Format String | Resulting String |
|---|---|---|
| 00:00:00.000 AM 1/1/2001 (Universal Time) | %<%.3X %x>T | 12:00:00.000 AM 01/01/2001 |
| 00:00:00.000 AM 1/1/2001 (Universal Time) | %<%Y.%m.%d>T | 2001.01.01 |
| 00:00:00.000 AM 1/1/2001 (Universal Time) | %^<%.3X %x>T | 06:00:00.000 AM 12/31/2000 |
%T specifies absolute time.
- Any information you include within the embedded time format (between < and >) indicates how you want to format the absolute time. For more information on the embedded time format codes, refer to Time-Specific Format Codes.
- The format, including the punctuation, changes based on the regional settings of the computer. The time changes based on the configured time zone for the computer.
- Add ^ to format the time in Universal Time.
String (%s) Example
| Argument | Format String | Resulting String |
|---|---|---|
| Smith John | Name: %s, %s. | Name: Smith, John. |
| Hello, World | String: %10.6s | String: Hello, |
- %s is valid for both formatting and scanning. You can use %s for both strings and files.
- In the first example, the format string uses multiple format
specifiers. To accomplish this result, do the following:
- Provide the family name (Smith) to input 1 of Format Into String.
- Expand Format Into String to add a second input by clicking and dragging on the bottom of the function. Provide the given name (John) to the resulting input 2.
- Enter the provided format string. Because the format string includes two % delimiters, the format string includes two format specifiers. The number of format specifiers in the format string must match the number of inputs to the function. LabVIEW interprets the characters that are not part of a format specifier as literal text to add to the resulting string.
- In the second example, .6 controls the precision of the string. .6 specifies to use at most six characters from the string Hello, World. 10 is the width: LabVIEW pads the string with spaces so the total string length is equal to ten.
Variable Order (%$) Example
| Argument | Format String | Resulting String |
|---|---|---|
| Smith John | %2$s %1$s | John Smith |
In this example, Smith is the first variable and John is the second variable.
- If you use $ in the format string for a particular variable, subsequent syntax elements that are not preceded by $ apply to the next variable.
- To improve readability when you use $ for a variable, use $ for any other variables in the string.
Literal Percent Character Example (%%)
| Argument | Format String | Resulting String |
|---|---|---|
| Empty argument | %% | % |
%% does not add a terminal to the Format Into String or Scan From String functions.
Related Information
- About Format Specifiers
Format specifiers define how LabVIEW functions interpret strings. Understand the terminology of format specifiers and how they differ when used for formatting strings or scanning strings.
- Units in LabVIEW
In LabVIEW, you can associate physical units of measure with floating-point numeric data. Use units to simplify conversions between different physical measurements and to simplify arithmetic with physical quantities, for example.
- Characters Numeric Controls and Indicators Accept