Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

JavaScript: Cast a float as an integer?

Discussion in 'Scripting' started by Tomas, May 8, 2007.

  1. Tomas

    Tomas

    Joined:
    Mar 30, 2007
    Posts:
    21
    Hello,

    How can I cast a float as a integer in JavaScript?

    Ive tried:

    var Aint = (int) Bfloat;
    var Aint = int (Bfloat);

    but both launch an error

    thanks a lot
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    How about:
    Code (csharp):
    1. var AInt : int = BFloat;
    -Jon
     
  3. Tomas

    Tomas

    Joined:
    Mar 30, 2007
    Posts:
    21
    Thank you so much
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's also parseInt(), which works for floats and (more importantly) strings.

    --Eric