Java Format Specifier Uppercase

Description

Uppercase versions format specifiers cause the conversion to use uppercase where appropriate.

Uppercase List

SpecifierEffect
%AUppercase 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.
%BUppercases the values true and false.
%EUppercase the e symbol that indicates the exponent.
%GUppercase the e symbol that indicates the exponent.
%HUppercase the hexadecimal digits a through f to A through F.
%SUppercases the corresponding string.
%TUppercase alphabetical output.
%XUppercase 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);
  }
}




















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter