Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

is this a way to convert String to integer?

Posted on 2004-11-30
16
Medium Priority
?
9,538 Views
Last Modified: 2010-08-05
is this a way to convert String to integer?

Integer currentStartingPrice = new Integer((String)startingPrice.getText());
int price = currentStartingPrice;

thx
Tom


0
Comment
Question by:tom_mk
  • 6
  • 4
  • 3
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12711289
Integer currentStartingPrice = new Integer(startingPrice.getText());
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 12711301
Or just

int price = Integer.parseInt(startingPrice.getText());

0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12711426
int       i = Integer.parseInt(s);
long       l = Long.parseLong(s);
float       f = Float.parseFloat(s);
double       d = Double.parseDouble(s);

Convert integers with some base (radix) other than 10 by using these two methods.
if you want to convert numbers in hexadecimal or base 2 ... use

int       i = Integer.parseInt(s, radix);
long       l = Long.parseLong(s, radix);

For example, to convert a string containing the hexadecimal number "F7" to an integer, call

i = Integer.parseInt("F7", 16)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:kiranhk
ID: 12711433
0
 

Author Comment

by:tom_mk
ID: 12711722
i need to import this

import java.lang.*;
import java.lang.Object.*;

is tat correct?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12711730
No. java.lang.* doesn't need importing
0
 

Author Comment

by:tom_mk
ID: 12711736
so only import java.lang.Object.*;  ??
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12711737
by default/implicitly the java.lang package is available for the JVM
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12711748
>>so only import java.lang.Object.*;  ??

Dont import anything in lang
0
 

Author Comment

by:tom_mk
ID: 12711765
i did some silly mistake..

i solved the prob already

thxx
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12711774
Can you tell me why you accepted an answer that merely repeats the one i'd already given?
0
 

Author Comment

by:tom_mk
ID: 12712823
i accidentally press the wrong button though..

i just kinda hurry when i clicked. and i don't know how to cancle that :(
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12715238
>>and i don't know how to cancle that :(

By reopening the question ;-) i'll get it done
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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 …
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

810 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