What's Here?
- Members: 148,779
- Replies: 504,899
- Topics: 79,513
- Snippets: 2,661
- Tutorials: 705
- Total Online: 1,996
- Members: 85
- Guests: 1,911
|
How to impliment the decimal format class with an example
|
Submitted By: William_Wilson
|
|
Rating:

|
|
Views: 13,070 |
Language: Java
|
|
Last Modified: September 9, 2008 |
|
Instructions: copy code sections and modify to your needs, decimalformat uses a string template to design your output. |
Snippet
//you first need to import the DecimalFormat class:
import java.text.DecimalFormat;
//then create a format object. this object can be used with doubles, as it uses a [i]decimal[/i]. It uses a template String to [b]teach[/b] Java how to ouput the objects.
//This example will be used as a standard format of money:
//Now that you have a money object. (declared either globally or locally) you can now [b]format[/b] your objects
//Note this example uses only 2 decimal places and a $, but any symbols or length is available.
//As an example of prniting a double value:
double amount = 4.333333333;
System. out. println(money. format(amount ));
//what will be printed is: $4.33 as described by the template, this handles your percision and dollar sign with a single template!
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|