“JavaScript convertit float en int” Réponses codées

JavaScript convertit float en 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 
Grepper

float javascript à 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
Sparkling Skunk

Réponses similaires à “JavaScript convertit float en int”

Questions similaires à “JavaScript convertit float en int”

Plus de réponses similaires à “JavaScript convertit float en int” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code