Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Number Format Exception  RSS feed

 
mou haj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.NumberFormatException: 1000000000099
ihave a number 1000000000099 and im wanting to do parse in /parse long but im getting number format exception why??? please help
 
sriramakrishna besta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/* try this code...
1. if u have 1000000000099 as a String object, change it to Lang object and then to long
2. if u have 1000000000099 as a Long object chage it to long
--- see java.Lang package for details ---
*/
class help1
{
public static void main(String[] args)
{
String S="1000000000099";
/* trim() to remove extra spaces from the strng value */
Long L=new Long(S.trim());
long l=L.longValue();
System.out.println("S is "+S);
System.out.println("L is "+L);
System.out.println("l is "+l);
}
}
regards
ramakrishna
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sriramakrishna besta:
1. if u have 1000000000099 as a String object, change it to Lang object and then to long
2. if u have 1000000000099 as a Long object chage it to long
In actual fact, the constructor for Long(String) uses Long.parseLong(String) to convert the string into a long first! Creating a Long object just to parse a string is a waste of perfectly good CPU cycles; Long.parseLong() should do the job.
Without more information it's difficult to say what's wrong.
- Peter

[This message has been edited by Peter den Haan (edited October 03, 2001).]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!