[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

convert string (with decimals) to Long

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
royjayd
Asked:
royjayd
  • 2
2 Solutions
 
thisstupidservicewontletmeusemynameCommented:
4.65 is not a Long value. Use Float.parseFloat or Double.parseDouble for floating point values.
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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
 
royjaydAuthor Commented:
mccarl
if you dont mind, can you answer this..thanks
http://www.experts-exchange.com/Programming/Languages/Java/Q_28005139.html
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Yeah, I was getting back to that question... Check it now, I have made a comment! :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now