Is there a list of all the formatting codes available?
This is one example:
“%f” (float) formatting code for the VEX IQ LCD Display
I specifically need to display the value of a string.
Is there a list of all the formatting codes available?
This is one example:
“%f” (float) formatting code for the VEX IQ LCD Display
I specifically need to display the value of a string.
Hi jsan31,
Are you using RobotC or Modkit?
If you are using RobotC, in addition to %f (float) and %d (integer), you can also use %s for strings. For example, this example code is from the RobotC help file:
while(true) // infinite loop:
{
string s1 = "ROBOTC"; // create the string named s1, "ROBOTC"
displayString(3, "%s", s1); // display the string, 's1' on line 3
sleep(50); // wait 50 milliseconds (helps refresh rate of LCD screen)
}
Regards,
To add to this, below is a snippet from our string formatting pages in the ROBOTC support docs. I’m currently in the process of adding this to the VEX IQ and VEX Cortex pages (under their respective ‘Display’ pages in the Function Library section(s)) and it should be available for the next build.
%d or %i
Signed decimal integer
"%d"
4246
%e
Scientific notation (mantise/exponent) using e character
"%e"
3.9265e+2
%E
Scientific notation (mantise/exponent) using E character
"%E"
3.9265E+2
%f
Decimal floating point number
"%f"
3.14159
%o
Signed octal
"%o"
157
%s
String of characters
"%s"
ROBOTC
%x
Unsigned hexadecimal integer
"%x"
7fa
%X
Unsigned hexadecimal integer (capital letters)
"%X"
7FA
%c
Character
"%c"
b
NOTE on Displaying Digits: When displaying floats, for example, you can tell ROBOTC how many decimals places to display. This is standard across all ‘C’ - like programing languages. For example, if your float is PI (3.14159265), but you only want to dispay “3.14”, your string should contain, “%1.2f”.
The number before the decimal is how many digits before the decimal you wish to display, while the number after the decimal is how many digits after the decimal you wish to display. So “%1.2f” tells us to display one digit before the decimal and two digits after the decimal, with “3.14” as the final result.
The tag can also contain flags, width, .precision and modifiers sub-specifiers, which are optional and follow these specifications:
%d
Prints a decimal integer
50
%6d
Prints a decimal integer, at least 6 characters wide
_ _ _ _ 50
%f
Prints a floating point number
50.5
%6f
Prints a floating point number, at least 6 characters wide
_ _ _ 50.5
%.2f
Prints a floating point number, with at least 2 decimal places
50.50
%6.2f
Prints a floating point number, with at least 6 characters wide and 2 decimal places
__ 50.50
Note: Underscore ( _ ) character denotes a space.
Code example:
task main()
{
int whole = 10;
float decimal = 3.14;
string text = "ROBOTC!";
displayTextLine(0,"Integer: %d", whole);
displayTextLine(1,"Float: %f", decimal);
displayTextLine(2,"String: %s", text);
displayTextLine(3, "Combo: %d, %.4f, %s", whole, decimal, text);
while(true);
}