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 07-10-2008, 04:11 PM
Member
 
Join Date: Jul 2008
Posts: 1
sakthivel123 is on a distinguished road
Double Value problem
Hi all,

I have a Double with this value 136546.215454 and I want to convert it to: 136546.21 How can I do that (Only 2 decimals after ".")

Regards,
Sakthivel
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-10-2008, 05:55 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 783
Nicholas Jordan is on a distinguished road
There is a NumberFormat somewhere, I can help you find it.

google: "java NumberFormat"
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-10-2008, 06:18 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Is it the display of the Double you want to change(ie when you print it) or the value of the Double? That is you want the value of the Double to be:136546.21000000 ie all zeros after the .21
A way might be to multiple the value by 100, convert to long and then convert to Double and divide by 100. For example:
Code:
double d = 1234.21345666; d = d * 100.0; long dI = (long)d; double e = ((double) dI)/ 100.0; System.out.println("d=" + d + ", e=" + e); //d=123421.34566600001, e=1234.21
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
Double Buffering problem aprenz Java Applets 0 05-28-2008 06:26 AM
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
How to round a double? Valeriano New To Java 1 05-31-2007 05:50 PM


All times are GMT +3. The time now is 03:05 AM.


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