What's Here?
- Members: 117,542
- Replies: 431,820
- Topics: 66,663
- Snippets: 2,394
- Tutorials: 631
- Total Online: 1,663
- Members: 66
- Guests: 1,597
Who's Online?
|
Welcome to Dream.In.Code |
|
Getting Java Help is Easy!
Join 117,542 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 1,663 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
How to impliment the decimal format class with an example
|
Submitted By: William_Wilson
|
|
Rating:
 
|
|
Views: 10,517 |
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
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|