JS Reference
Service Workers
ESModule Tips
NodeJS Tips
Javascript Tips

Hexadecimal Number to Decimal Number

Using parseInt, Number, and BigInt

Hex Number to Decimal Conversion

Different Methods for Conversion

To Convert Hexadecimal to Decimal number, following options are available using parseInt, Number, BigInt

Using parseInt

script.js
Copy
const hexNumber = "1f300";
const decimal = parseInt(hex, 16);

console.log("Decimal Number: ", decimal); // Output: Decimal Number: 127744

Using BigInt

script.js
Copy
const largeHex = "EFEFAAABB1234F";
// Standard parseInt loses accuracy and precision:
console.log(parseInt(largeHex, 16)); // Output: 67536035737838420

// Using BigInt for large number and good accuracy:
const accurateDecimal = BigInt("0x" + largeHex).toString();
console.log(accurateDecimal); // Output: 67536035737838415

Using Number

script.js
Copy
const hex = "0xAA";
let num = Number(hex); //Needs to have 0x prefix (detect automatically)
console.log(num); // Output: 170