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 12-24-2007, 02:02 PM
Member
 
Join Date: Dec 2007
Posts: 1
srini is on a distinguished road
Converting String to Double
Hi All,
Can any one help me.When I converting String to long ,It shwoing Exponent value and throwing numberformat exception.
I want out put like this 99998900001.00.
I have given input like this 99998900001.00.

String stotal=request.getParameter("amt");
sop( stotal);
long damount=Long.parseLong(stotal);
sop( damount);

stotal= 99998900001.00
throw numberformateexception
damount = 9.9998900001E10

Last edited by srini : 12-24-2007 at 02:08 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-24-2007, 10:03 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
By default in java, any number with a decimal in it is considered/read/treated as a double data type. To get this into a long data type you would have to cast it to a long. But then you won't get it to print out as a double, ie, with two decimal places.
Code:
public class Test { public static void main(String[] args) { String stotal = "99998900001.00"; // NumberFormatException // long error = Long.parseLong(stotal); double okay = Double.parseDouble(stotal); System.out.printf("okay = %.2f%n", okay); long toLong = (long)okay; long again = Double.valueOf(stotal).longValue(); System.out.printf("toLong = %d again = %d%n", toLong, again); } }
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
Converting object to string Preethi New To Java 4 06-14-2008 05:29 AM
Converting URL to URI Java Tip Java Tips 0 12-26-2007 12:15 PM
Converting Epoch to string Date amyedwards New To Java 3 12-15-2007 12:33 AM
convert string to a double? javaMike Advanced Java 2 11-27-2007 05:10 AM
help with converting to JApplet Simmy AWT / Swing 2 08-09-2007 10:45 AM


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


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