How to convert decimal to hex in JavaScript ? Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a number and the task is to convert the number from decimal to hex. This can be done by using toString() method. It takes the parameter which is the base of the converted string. In this case, the base will be 16. Syntax: decimalNumber.toString( radix ) Parameters: decimalNumber: It holds the number in a decimal format that needs to be converted.radix: It holds the base of the number system in which the number is converted. Example 1: This example converts 20 to a hex number system. JavaScript let GFG_Var = 20; function myGFG() { let GFG_Var2 = GFG_Var.toString(16); console.log("Hex of " + GFG_Var + " is = " + GFG_Var2); } myGFG(); OutputHex of 20 is = 14 Example 2: This example converts a number 100 to its octal number system. JavaScript let GFG_Var = 100; function myGFG() { let GFG_Var2 = GFG_Var.toString(8); console.log("Octal of " + GFG_Var + " is = " + GFG_Var2); } myGFG(); OutputOctal of 100 is = 144 Comment More infoAdvertise with us Next Article Octal to Decimal conversion using JavaScript P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to convert decimal to octal in JavaScript ? In this article, we are given a number and the task is to convert the number from decimal to octal. This can be done by using number.toString(8) method. It takes the parameter which is the base of the converted string. In this case, the base will be 8. Syntax: number.toString(8) The below examples s 2 min read How to convert binary to decimal in JavaScript? A binary number is a number expressed in the binary numeral system, which uses only two symbols 0 and 1. Decimal numbers are base 10 in a JavaScript number system that uses 10 digits from 0 to 9. We are given a number as Binary input we have to convert it into decimal in JavaScript and print the res 3 min read How to convert string into float in JavaScript? In this article, we will convert a string into a float in Javascript. We can convert a string into a float in JavaScript by using some methods which are described below: Methods to Concert String into Float:Table of Content Method 1: By using Type Conversion of JavaScriptMethod 2: By using parseFloa 6 min read How to convert Hex to RGBA value using JavaScript ? Given a color hex code and the task is to convert Hex Value to RGBA value. Here are few of the mostly techniques discussed with the help of JavaScript. Approach 1: First check the passed Hex value is valid or not through a Regular Expression.Then get the hex value content after '#' by using .slice() 3 min read Octal to Decimal conversion using JavaScript An octal number is a number system that uses a base of 8 and numbers are represented using the digits 0 through 7. Decimal numbers are a base 10 number system which uses 10 digits from 0 to 9. We are given a number a octal number and we have to convert it into decimal in JavaScript and print the res 3 min read How to Convert Integer to Its Character Equivalent in JavaScript? In this article, we will see how to convert an integer to its character equivalent using JavaScript. Method Used: fromCharCode()This method is used to create a string from a given sequence of Unicode (Ascii is the part of Unicode). This method returns a string, not a string object. JavaScript let s 2 min read Like