?
Solved

convert string (with decimals) to Long

Posted on 2013-02-06
4
Medium Priority
?
327 Views
Last Modified: 2013-02-06
hi guys

I have a method like this
public static String getAmount(String amt){
            String value = "";
            Long longVal = Long.parseLong(amt)* 100000000000;
            value = ""+longVal;
            return value;
      }

when amt is "45.65" , it throws numberformatexception.
any ideas how i can resolve this ?

thanks very much
0
Comment
Question by:royjayd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Assisted Solution

by:thisstupidservicewontletmeusemyname
thisstupidservicewontletmeusemyname earned 600 total points
ID: 38861926
4.65 is not a Long value. Use Float.parseFloat or Double.parseDouble for floating point values.
0
 
LVL 36

Accepted Solution

by:
mccarl earned 600 total points
ID: 38861927
Long is the data type for a long integer, and 45.65 is not an integer.

Change Long to Double or BigDecimal, these are data types that can handle the fractional numbers.
0
 

Author Comment

by:royjayd
ID: 38861972
mccarl
if you dont mind, can you answer this..thanks
http://www.experts-exchange.com/Programming/Languages/Java/Q_28005139.html
0
 
LVL 36

Expert Comment

by:mccarl
ID: 38862018
Yeah, I was getting back to that question... Check it now, I have made a comment! :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question