The Artima Developer Community
Sponsored Link

Java Answers Forum
String to Integer problem

1 reply on 1 page. Most recent reply: Jul 16, 2006 1:24 PM by Dave Hinton

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Zark_mk Markovic

Posts: 1
Nickname: zarkmc
Registered: Jul, 2006

String to Integer problem Posted: Jul 15, 2006 3:25 AM
Reply to this message Reply
Advertisement
Hi,

I'm new to JSP and I have problems converting String with decimal numbers to Integer.

I have a string with 8 decimals, it gets the vallue of a column in database. I would like to make a sum of all the rows. Example:

while (rs.next()) {
String sumi = rs.getString("amountduration");
int sum = Integer.parseInt(sumi);
// Code for making the sum
// ..
}

It appears that "Integer.parseInt" works only if the string doesn't have any decimals.

Thanks
Zark


Dave Hinton

Posts: 42
Nickname: catbells
Registered: Oct, 2003

Re: String to Integer problem Posted: Jul 16, 2006 1:24 PM
Reply to this message Reply
Integers are whole numbers. They have no fractional part.

You should be using doubles instead.

double sum = Double.parseDouble(sumi);

Flat View: This topic has 1 reply on 1 page
Topic: Inside the JVM -- Threading Previous Topic   Next Topic Topic: How to copy from one array to another array?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use