Java Format Comma

In this chapter you will learn:

  1. What is grouping separators
  2. Syntax for grouping separators
  3. How to add grouping specifiers for large value numbers

Description

, adds grouping separators to numeric values.

Syntax

fmt.format("%,.2f", 1234567890.34);

Example

The comma (,) flag adds grouping specifiers.


import java.util.Formatter;
//from  w  w  w . j  av a  2  s . c om
public class Main {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();
    fmt.format("%,.2f", 1234567890.34); 
    System.out.println(fmt);
  }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. What is Java Format Alternate Conversion
  2. Syntax for Java Format Alternate Conversion
  3. Example - Java Format Alternate Conversion
  4. Example - the hexadecimal number
  5. Example - the octal number
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