How to convert string containing decimal point into integer
in java? For example given a string like "3.14" as input how
to get integer 3 as result.

Answers were Sorted based on User's Feedback



How to convert string containing decimal point into integer in java? For example given a string lik..

Answer / indresh_ips

class StringToInt {
public static void main (String[] args) {
String s="3.14";
double i=Double.parseDouble(s);
int i1=(int)i;
System.out.println (i1);

}
}

Is This Answer Correct ?    37 Yes 4 No

How to convert string containing decimal point into integer in java? For example given a string lik..

Answer / pradeep

/* How to convert string containing decimal point into integer
in java? For example given a string like "3.14" as input how
to get integer 3 as result. */

String myStr = "3.14";
Int myInt = Float.valueOf(myStr).intvalue();

Is This Answer Correct ?    43 Yes 13 No

How to convert string containing decimal point into integer in java? For example given a string lik..

Answer / sivadasan

Simple ..

String str="3.14";
int i = Double.valueOf(str).intValue();

// we can use Float instead of Double

Output = 3.

Is This Answer Correct ?    8 Yes 0 No

How to convert string containing decimal point into integer in java? For example given a string lik..

Answer / troya

String str = "5.22";
Int result = Float.valueOf(mystr).intValue();
// value of result is 5

Is This Answer Correct ?    6 Yes 1 No

How to convert string containing decimal point into integer in java? For example given a string lik..

Answer / shiva kumar

/***************************************************/

import java.io.*;

class StringToInt
{
public static void main(String a[]) throws
IOException
{
String s;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
do{
s=br.readLine();
System.out.println("U R Sting
is: "+s);
}while(s.equals(" "));
try
{
double d = new Double(s);
int j = (int)d;
System.out.println(j);
}catch(NumberFormatException e)
{
System.out.println(" Your String is
Not a Number:.. ");
}
}
}

Is This Answer Correct ?    8 Yes 4 No

How to convert string containing decimal point into integer in java? For example given a string lik..

Answer / subramanyam

I don't know

Is This Answer Correct ?    15 Yes 17 No

How to convert string containing decimal point into integer in java? For example given a string lik..

Answer / rajasekaran.p

For the above given question 3 is answer while converting
decimal to integer

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More J2EE Code Interview Questions

Can we change the validator-rules.xml for our own validations in struts??

0 Answers   Mastek,


Write Down Steps Using SAX Parser

0 Answers  


i am trying to intigrate ejb and hibernate ,from session facade i am callind dao implemented through hibernate,i am getting a ClassDefNotFoundException for this org/hibernate/Session i ve set the class path at build path and in setEnv in weblogic still .........

0 Answers  


How to read MS-word document in java without displaying junk (unnecessary) data?

5 Answers   Cognizant,


Can you forward data from a servlet to a regular .java class that is not a servlet?

3 Answers  






how to find reverse of string without string funtion of java.

2 Answers  


plz send code for manage group of hotels in j2ee frontend:J2EE Backend: DB2 Express

0 Answers   TCS,


Where can i find some sample applications for different J2EE frameworks like Spring,Struts ,JSF, Hibernate etc ??

0 Answers  


How to get one hasmap value in another hashmap ,only value not key

0 Answers   CTS,


design an on-line bus reservation application using html jsp servlet and jdbc. also implement session management and cookies

0 Answers  


exception org.apache.jasper.JasperException: java.lang.NullPointerException org.apache.jasper.servlet.JspServletWrapper.handleJs pException(JspServletWrapper.java:491) org.apache.jasper.servlet.JspServletWrapper.service( JspServletWrapper.java:419) org.apache.jasper.servlet.JspServlet.serviceJspFile( JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServ let.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.j ava:717) root cause java.lang.NullPointerException org.apache.struts.taglib.TagUtils.retrieveMessageRes ources(TagUtils.java:1175) org.apache.struts.taglib.TagUtils.message(TagUtils.j ava:1038) org.apache.struts.taglib.bean.MessageTag.doStartTag( MessageTag.java:224) org.apache.jsp.register_jsp._jspx_meth_bean_005fmess age_005f0(register_jsp.java:138) org.apache.jsp.register_jsp._jspService(register_jsp .java:94) org.apache.jasper.runtime.HttpJspBase.service(HttpJs pBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.j ava:717) org.apache.jasper.servlet.JspServletWrapper.service( JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile( JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServ let.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.j ava:717)

0 Answers  


code inside filter to restrict users to access a servlet component .

1 Answers   NIIT,


Categories