Is it possible to convert a float to an int in Javascript? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Is it possible to convert a float to an int in Javascript?

NickFNickF USAPosts: 132Member

Can someone please explain whether it is possible to convert a float to an int in Javascript?

Tagged:

Comments

  • thealtusthealtus Posts: 1Member

    Technically speaking, all numbers in Javascript are floats. However, if you'd like to simply truncate a float into an integer, there are a few ways to do this:
    1. Using Math.floor, Math.round, and Math.ceil.
    2. Using the bitwise OR operator.

  • JadokJadok Nantes, FrancePosts: 4Member

    You can convert your number with the function parseInt, which equal to Math.floor

  • Elizabeth_KeenElizabeth_Keen USAPosts: 0Member

    Hi
    You can use any of the below methods
    var intvalue = Math.floor( floatvalue );
    var intvalue = Math.ceil( floatvalue );
    var intvalue = Math.round( floatvalue );
    Hope this helps.
    ati-erp.com

  • Elizabeth_KeenElizabeth_Keen USAPosts: 0Member

    Hi
    You can use any of the below methods:
    var intvalue = Math.floor( floatvalue );
    var intvalue = Math.ceil( floatvalue );
    var intvalue = Math.round( floatvalue );
    Hope this helps.
    ati-erp.com

  • Elizabeth_KeenElizabeth_Keen USAPosts: 0Member

    Hi
    You can use any of the below methods:
    var intvalue = Math.floor( floatvalue );
    var intvalue = Math.ceil( floatvalue );
    var intvalue = Math.round( floatvalue );
    Hope this helps.
    ati-erp.com

Sign In or Register to comment.