I practiced another CodeWar problem today: RGB To Hex Conversion
To put it simply, the problem is to convert RGB numbers to hexadecimal and output them.
|
|
If you convert directly with hex, you get an extra “0x” and “00” becomes “0”. I wondered if there was a function like sprintf, and found this site: String formatting like C’s sprintf
Surprisingly, if you specify the format, the number is converted directly! You can also specify the number of digits.
Here is my answer:
|
|
So convenient~