Format Number as Currency
From Java Example Source Code
Contents |
[edit] Overview - Format Number as Currency
This Java example program shows how to format number as currency.
[edit] Java Source Code
- Package: example.numberformat
- File: Mortgage.java
package example.numberformat; import java.text.NumberFormat; public class Mortgage { public static void main(String[] args) { double payment = Math.random() * 1000; System.out.println("Your payment is "); NumberFormat nf = NumberFormat.getCurrencyInstance(); System.out.println(nf.format(payment)); } }
[edit] What Result You Can Get
Run the program, you will get:
Your payment is $147.14
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
