converter string para int javascript code example

Example 1: how to convert string to int js

let string = "1";
let num = parseInt(string);
//num will equal 1 as a int

Example 2: javascript string to integer

<script language="JavaScript" type="text/javascript"> 
var a = "3.3445";
var c = parseInt(a);
alert(c);
</script>

Example 3: convert string to integer javascript

const stringPrices = ['5.47', '3.12', '8.00', '5.63', '10.70'];
let priceTotal = 0;

// priceTotal should be: 32.92
// Write your code below

stringPrices.forEach(stringPrice => {
price = parseFloat(stringPrice);
  priceTotal += price;
});

Example 4: parseint js

parseInt(" 0xF", 16);
parseInt(" F", 16);
parseInt("17", 8);
parseInt(021, 8);
parseInt("015", 10);
parseInt(15.99, 10);
parseInt("FXX123", 16);
parseInt("1111", 2);
parseInt("15*3", 10);
parseInt("15e2", 10);
parseInt("15px", 10);
parseInt("12", 13);

//Return: 15

Tags:

Java Example