Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

convert string (with decimals) to Long

Posted on 2013-02-06
4
Medium Priority
?
328 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

636 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