Answers for "javascript float to int"

14

javascript float to int

function float2int (value) {
    return value | 0;
}

float2int(3.75); //3 - always just truncates decimals

//other options
Math.floor( 3.75 );//3 - goes to floor , note (-3.75 = -4)
Math.ceil( 3.75 ); //4 - goes to ceiling, note (-3.75 = -3)
Math.round( 3.75 );//4
Posted by: Guest on July-24-2019
1

javascript number length

var num = 1234
number.toString().length; // 4
Posted by: Guest on April-17-2020
0

get the whole value of a number javascript

var value = 2.9802453587962963;
var wholeNum = Math.floor(value);
console.log(wholeNum);  // output ==> 2
Posted by: Guest on September-01-2020
1

javascript quick float to integer

console.log(23.9 | 0);  // Result: 23
console.log(-23.9 | 0); // Result: -23
Posted by: Guest on November-25-2020
0

javascript float to int

// x = Number.MAX_SAFE_INTEGER/10 * -1 // -900719925474099.1

// value = x      // x=-900719925474099   x=-900719925474099.5 x=-900719925474099.6

Math.floor(value) // -900719925474099     -900719925474100     -900719925474100
Math.ceil(value)  // -900719925474099     -900719925474099     -900719925474099
Math.round(value) // -900719925474099     -900719925474099     -900719925474100
Math.trunc(value) // -900719925474099     -900719925474099     -900719925474099
parseInt(value)   // -900719925474099     -900719925474099     -900719925474099
value | 0         // -858993459           -858993459           -858993459
~~value           // -858993459           -858993459           -858993459
value >> 0        // -858993459           -858993459           -858993459
value >>> 0       //  3435973837           3435973837           3435973837
value - value % 1 // -900719925474099     -900719925474099     -900719925474099
Posted by: Guest on July-27-2021
2

js int

var myInt = 69420

1+1//int
1+"1"//string
Posted by: Guest on April-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language