Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-31-2007, 05:49 PM
Member
 
Join Date: May 2007
Posts: 10
Valeriano is on a distinguished road
How to round a double?
I have a method that prints out two doubles after a series of mathematical operations. I need the doubles to be displayed with two decimal places. I don't need to do anything with the rounded doubles, I just need to print them out. How can i do that?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-31-2007, 05:50 PM
Member
 
Join Date: May 2007
Posts: 11
Hasan is on a distinguished road
You can use DecimalFormat class for printing.

Code:
double x = 1.20136; DecimalFormat f = new DecimalFormat("#.##"); f.format(x);
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating sin of a double value Java Tip Java Tips 0 01-13-2008 10:13 PM
transforming double to int AlejandroPenton New To Java 2 12-11-2007 03:34 AM
Getting smallest possible Double value Java Tip Java Tips 0 12-06-2007 04:15 PM
round to two decimal places javaMike New To Java 1 11-26-2007 11:46 PM
How to determine if the value of a JTextField is double nemo New To Java 1 05-20-2007 01:19 PM


All times are GMT +3. The time now is 01:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org