Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 21-11-2009
Members
 
Join Date: Oct 2009
Posts: 10
How to cast float value into integer in javascript

Does any one how to cast to an integer in JavaScript? I've searched through google but I could not find how to convert float value into an int. Any help will be greatly appreciated.
Reply With Quote
  #2  
Old 21-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to cast float value into integer in javascript

To cast float value into integer in javascript, we have to use the function or method "stringFloat() to convert a string value to float.
Code:
<script language="javascript">
var d = 32;
var g = 333;
var f = d.toString()+g;
document.write(" to String function "+c);
</script>

Result:
to String function -> 32333
Reply With Quote
  #3  
Old 21-11-2009
Member
 
Join Date: Jan 2009
Posts: 199
Re: How to cast float value into integer in javascript

Code:
public class Strfloat
{

  public static void main (String[] args)
  {

    // String s = "fred";    

    String d = "100.00";

    try
    {
      float g = Float.valueOf(d.trim()).floatValue();
      System.out.println("float d = " + d);
    }
    catch (NumberFormatException nfe)
    {
      System.out.println("NumberFormatException: " + nfe.getMessage());
    }
  }
}
Reply With Quote
  #4  
Old 21-11-2009
Member
 
Join Date: Dec 2008
Posts: 177
Re: How to cast float value into integer in javascript

Cast string value into integer in javascript :
Code:
public class StringTFloat{
  public static void main(String[] args) {
    System.out.println("Cast string value into integer in javascript");
    String s = "5";
    Float d = new Float(str);
    double g = f.doubleValue();
    System.out.println("float value:"+d);
    System.out.println("double value:"+g);
  }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to cast float value into integer in javascript"
Thread Thread Starter Forum Replies Last Post
Coversion of Cast string as int in Javascript LaMarcus Software Development 5 14-10-2010 03:59 AM
Casting int to float in C Jensen Ackles Software Development 4 05-04-2010 05:08 PM
Difference between double and float garfield1 Software Development 5 06-03-2010 04:13 PM
CSS : How to float outside parent div Valerian Software Development 4 21-05-2009 12:03 PM
How to make a CSS div float OVER another div Warner Software Development 3 21-05-2009 10:50 AM


All times are GMT +5.5. The time now is 08:01 PM.