?
Solved

How to store an integer value from excel without the decimal points

Posted on 2006-05-30
5
Medium Priority
?
196 Views
Last Modified: 2010-03-31
Hi

I have an ID field in excel, which I read from a java application. I store the ID field in a  String variable, but the problem is that it stores the value with a .0 at the end. So for eg 456 is stored as 456.0. How can i store the value like 456 only. Any help will be greatly appreciated
0
Comment
Question by:royalcyber
  • 4
5 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 16791940
String a = "456.0";
int i = Integer.parseInt(a.substring(0, a.indexOf('.')));

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16791945
But only if you are certain that the   .    is present.

;JOOP!
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 1000 total points
ID: 16791971
More secure:

  String a = "456.0";
.............

  int index;

      if((index = a.indexOf('.')) >= 0)
      {
         a = a.substring(0, index);
      }

// a is now shortened to a string without .xxx  to any purpose.

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16792335
You could do

String a = "" + (int)Double.parseDouble(originalString);
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16794000
:)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
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 about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

839 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