Solved

convert string (with decimals) to Long

Posted on 2013-02-06
4
324 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
ID: 38861926
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
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 35

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 52
why cannot we forward request once the response is committed 2 46
tomcat not starting 6 68
Convert from a json string array to a Java object 3 53
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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 …

832 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