In this example we are going to format a decimal value.
In this example we are talking a double value. We are creating an object of DecimalFormat(String format_type) class .In DecimalFormat class we are passing "0.000" .This is used to create an decimal format which display three digits after decimal point. We are using NumberFormat to store the reference of object of DecimalFormat with name of formatter. To apply the format on double value we are using format() method.
The code of the program is given below:
The output of the program is given below:
C:\convert\rajesh\completed>java DecimalFormatExample The Decimal Value is:2192.015
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: June 29, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles