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

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

Comments

  • 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, France

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

  • 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

  • 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

  • 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.

Howdy, Stranger!

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

Categories