Results 1 to 2 of 2
Thread: Converting String to Double
- 12-24-2007, 12:02 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 1
- Rep Power
- 0
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.9998900001E10Last edited by srini; 12-24-2007 at 12:08 PM.
- 12-24-2007, 08:03 PM #2
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.
Java 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); } }
Similar Threads
-
Converting object to string
By Preethi in forum New To JavaReplies: 4Last Post: 06-14-2008, 03:29 AM -
Converting URL to URI
By Java Tip in forum Java TipReplies: 0Last Post: 12-26-2007, 10:15 AM -
Converting Epoch to string Date
By amyedwards in forum New To JavaReplies: 3Last Post: 12-14-2007, 10:33 PM -
convert string to a double?
By javaMike in forum Advanced JavaReplies: 2Last Post: 11-27-2007, 03:10 AM -
help with converting to JApplet
By Simmy in forum AWT / SwingReplies: 2Last Post: 08-09-2007, 08:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks