Java Format Specifier Uppercase
Description
Uppercase versions format specifiers cause the conversion to use uppercase where appropriate.
Uppercase List
Specifier | Effect |
---|---|
%A | Uppercase the hexadecimal digits a through f to A through F. Also, the prefix 0x is displayed as 0X, and the p will be displayed as P. |
%B | Uppercases the values true and false. |
%E | Uppercase the e symbol that indicates the exponent. |
%G | Uppercase the e symbol that indicates the exponent. |
%H | Uppercase the hexadecimal digits a through f to A through F. |
%S | Uppercases the corresponding string. |
%T | Uppercase alphabetical output. |
%X | Uppercase the hexadecimal digits a through f to A through F. Also, the optional prefix 0x is displayed as 0X, if present. |
Example
The following code outputs value in uppercase hexadecimal.
import java.util.Formatter;
//from w w w. j a va 2 s .c o m
public class Main {
public static void main(String args[]) {
Formatter fmt = new Formatter();
fmt.format("%X", 250);
System.out.println(fmt);
}
}
The output:
Example 2
The following code does uppercase the e
symbol that indicates the exponent
import java.util.Formatter;
/*from www . j a v a 2s. co m*/
public class Main {
public static void main(String args[]) {
Formatter fmt = new Formatter();
fmt.format("%E", 123.1234);
System.out.println(fmt);
}
}