Solved

convert string (with decimals) to Long

Posted on 2013-02-06
4
319 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
  • 2
4 Comments
 
LVL 1

Assisted Solution

by:thisstupidservicewontletmeusemyname
thisstupidservicewontletmeusemyname earned 150 total points
Comment Utility
4.65 is not a Long value. Use Float.parseFloat or Double.parseDouble for floating point values.
0
 
LVL 35

Accepted Solution

by:
mccarl earned 150 total points
Comment Utility
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
Comment Utility
mccarl
if you dont mind, can you answer this..thanks
http://www.experts-exchange.com/Programming/Languages/Java/Q_28005139.html
0
 
LVL 35

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now