| Using VISA.NET > Formatted I/O > Using Printf > Printf Code Snippets > Formatting Integers |
An integer argument has a format specifier in one of the following forms:
%d%[-| |+|@[1|2|3|H|Q|B]][[0]width][.precision][,[arraySize]]d
%i%[-| |+|@[1|2|3|H|Q|B]][[0]width][.precision][,[arraySize]]i
%u%[-| |+|@[1|2|3|H|Q|B]][[0]width][.precision][,[arraySize]]u
%o%[-| |+|@[ Q|B]][[0]width][.precision][,[arraySize]]o
%x%[-| |+|@[H| B]][[0]width][.precision][,[arraySize]]x
%X%[-| |+|@[H| B]][[0]width][.precision][,[arraySize]]X
|
Modifier |
Interpretation |
|---|---|
|
Default Functionality |
The argument is interpreted as an integer. |
|
flags -, +, space, 0 @1, @2, @3 @H, @Q, @B |
Controls justification and padding of the output, as follows:
|
|
width |
Minimum field width of the output string. An asterisk (*) may be present in lieu of an integer width modifier, in which case an extra Int32 argument supplies the value. |
|
.precision |
Maximum number of characters to send. An asterisk (*) may be present in lieu of an integer precision modifier, in which case an extra Int32 argument supplies the value. |
|
[,[arraySize]] |
Format an array of integers converted to strings. If arraySize is specified, it is the maximum number of elements to include in the formatted array. An asterisk (*) may be present in lieu of an integer arraySize modifier, in which case an extra Int32 argument supplies the value. |
Remember that Printf is adding characters to the formatted write buffer. The comments after each Printf call show what character(s) are added to the formatted write buffer by that call. Assume that the io variable is a valid reference to IMessageBasedFormattedIO.
| No Modifiers |
Copy Code |
|---|---|
io.Printf("|%d|", 15); // Adds |15| io.Printf("|%i|", 15); // Adds |15| io.Printf("|%o|", 15); // Adds |17| (octal) io.Printf("|%u|", 15); // Adds |15| io.Printf("|%x|", 15); // Adds |f| (hexadecimal, lowercase) io.Printf("|%X|", 15); // Adds |F| (hexadecimal, uppercase) io.Printf("|%d|\n", -15); // Adds |-15|, sends buffer & flushes | |
| Sign Modifiers |
Copy Code |
|---|---|
io.Printf("|% d|", 15); // Adds | 15| io.Printf("|% d|", -15); // Adds |-15| io.Printf("|%+d|", 15); // Adds |+15| | |
| IEEE 488.2 Format Modifiers |
Copy Code |
|---|---|
io.Printf("|%@1d|", 15); // Adds |15| io.Printf("|%@2d|", 15); // Adds |15.000000| io.Printf("|%@38d|", 15); // Adds |1.500000E+001| io.Printf("|%-@B8d|", 15); // Adds |#B1111 | io.Printf("|%@Q8o|", 15); // Adds | #Q17| (octal) io.Printf("|%-@H8x|", 15); // Adds |#HF | (hexadecimal, lowercase) io.Printf("|%@H8X|", 15); // Adds | #HF| (hexadecimal, uppercase) | |
| Width and Precision Modifiers |
Copy Code |
|---|---|
io.Printf("|%8d|", 15); // Adds | 15| io.Printf("|%-*d|", 8, 15); // Adds |15 | io.Printf("|%.08d|", 15); // Adds |00000015| io.Printf("|%.0*d|", 8, 15); // Adds |00000015| | |
| PrintfArray |
Copy Code |
|---|---|
unsafe { Int32[] data = new Int32[] { 1, 1, 1 }; fixed (Int32* pdata = data) { io.PrintfArray("|%,2d|", pdata); // Adds |1,1| } } | |