0

I wish to convert the whiteHex variable to a decimal using the parseInt() function, and store it in a variable, whiteDecimal.

var whiteHex = 'ffffff';

var whiteDecimal = parseInt(whiteHex);

I am unsure if the above is correct or not. The reason being, that I then wish to subtract 1 from whiteDecimal and store it in a variable offWhiteDecimal. This is where I am getting stuck. How can I subtract one from the ffffff hex value? Am I missing something within the parseInt function?

ThanhPhan
  • 1,225
  • 2
  • 12
  • 24

1 Answers1

1

You're looking for this:

var whiteDecimal = parseInt(whiteHex, 16)
console.log(whiteDecimal - 1);

ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#Syntax

Nickolay
  • 29,618
  • 12
  • 101
  • 174