Results 1 to 4 of 4

Thread: How to cast float value into integer in javascript

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    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

  3. #3
    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());
        }
      }
    }

  4. #4
    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);
      }
    }

Similar Threads

  1. Coversion of Cast string as int in Javascript
    By LaMarcus in forum Software Development
    Replies: 5
    Last Post: 14-10-2010, 03:59 AM
  2. Casting int to float in C
    By Jensen Ackles in forum Software Development
    Replies: 4
    Last Post: 05-04-2010, 05:08 PM
  3. Difference between double and float
    By garfield1 in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 04:13 PM
  4. CSS : How to float outside parent div
    By Valerian in forum Software Development
    Replies: 4
    Last Post: 21-05-2009, 12:03 PM
  5. How to make a CSS div float OVER another div
    By Warner in forum Software Development
    Replies: 3
    Last Post: 21-05-2009, 10:50 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,202,716.57998 seconds with 17 queries