Java Format Specifier Uppercase

In this chapter you will learn:

  1. What is Format Specifier
  2. How and when to use Uppercase Option for Java Formatter
  3. How to uppercase hexadecimal
  4. How to uppercase e symbol

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;
/* www. ja 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;
//  ww  w.  ja  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);
  }
}

Next chapter...

What you will learn in the next chapter:

  1. How to use precision modifier
  2. Syntax for Precision Format
  3. Example - Precision Format
  4. How to format decimal value in precision
  5. How to control the number of significant digits for %g
  6. How to control string length with precision specifier
  7. Example - Specifying a Minimum Field Width
Home »
  Java Tutorial »
    Java Langauge »
      Java Data Format
Java Formatter Class
Java Format Specifier
Java Format Specifier Uppercase
Java Format Precision
Java Format Flags
Java Format Justifying Output
Java Format Negative and Positive
Java Format Line up Space
Java Format Parentheses
Java Format Zero Padding
Java Format Comma
Java Format Alternate Conversion
Java Format Argument Index
Java Format date time
Java Format Date