[javascript] How to convert decimal to hexadecimal in JavaScript

  • rgb(255, 255, 255) // returns FFFFFF

  • rgb(255, 255, 300) // returns FFFFFF

  • rgb(0,0,0) // returns 000000

  • rgb(148, 0, 211) // returns 9400D3

     function rgb(...values){
              return values.reduce((acc, cur) => {
                let val = cur >= 255 ? 'ff' : cur <= 0 ? '00' : Number(cur).toString(16);
                return acc + (val.length === 1 ? '0'+val : val);
              }, '').toUpperCase();
          }
    

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to hex

Transparent ARGB hex value How to convert a hex string to hex number Javascript: Unicode string to hex Converting Hexadecimal String to Decimal Integer Convert string to hex-string in C# Print a variable in hexadecimal in Python Convert ascii char[] to hexadecimal char[] in C Hex transparency in colors printf() formatting for hex Python Hexadecimal

Examples related to number-formatting

JavaScript Chart.js - Custom data formatting to display on tooltip Format / Suppress Scientific Notation from Python Pandas Aggregation Results Formula to convert date to number tSQL - Conversion from varchar to numeric works for all but integer Convert string to decimal number with 2 decimal places in Java What is ToString("N0") format? format a number with commas and decimals in C# (asp.net MVC3) SSRS custom number format Format telephone and credit card numbers in AngularJS How to format a number 0..9 to display with 2 digits (it's NOT a date)

Examples related to base

Remove category & tag base from WordPress url - without a plugin Equivalent of Super Keyword in C# How to convert an integer to a string in any base? Quickest way to convert a base 10 number to any base in .NET? How to convert decimal to hexadecimal in JavaScript