![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Programming tutorials All Knowledge Info and links to posted here |
![]() |
|
Java: Decimal Format to Easily Create Custom Output
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Administrator
Posts: 876
Join Date: Oct 2005
Rep Power: 10
IM:
|
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 decimal. It uses a template String to teach Java how to ouput the objects. *This example will be used as a standard format of money: DecimalFormat money = new DecimalFormat("$0.00"); Now that you have a money object. (declared either globally or locally) you can now format 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! |
|
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MXPLAY - Easily create mash ups | Spirit-X | Application Downloads | 0 | 30-Dec-2007 07:33 AM |
| Create Custom Flash Drive Icons | Anilrgowda | Microsoft Windows xp error | 0 | 23-Sep-2007 10:54 PM |
| Create your very own custom Decal for maps | Iphone | Graphic tutorials | 0 | 19-Apr-2007 01:04 AM |
| Format to 2 decimal places | Sangeetha | Knowledge Base | 1 | 27-Feb-2007 04:14 AM |
| Create a Custom Boot Logo for Windows Vista | Anilrgowda | Microsoft windows vista error | 0 | 05-Feb-2007 09:14 PM |