Print Currency Value

This program prints a currency value formatted with two decimal places.

Problem Statement

Write a Java program that prints a currency value.

Source Code

1 public class CurrencyFormat {
2 public static void main(String[] args) {
3 double price = 199.995;
4 System.out.printf("Price: Rs. %.2f - Eduinq", price);
5 }
6 }

Program Output

Price: Rs. 200.00 - Eduinq

Explanation

The %.2f format specifier rounds and formats the decimal value to two places, allowing the value to be printed as a currency amount, showing how to format numbers as currency.

Quick Links to Explore