Java Color Integer To RGB String In JavaScript
I'm trying to use some Java Color int values from a database in Javascript. What's the correct way to convert the Java color int (like -2147473665) to an RGB string (like '#ffff00'
Solution 1:
You need to handle signed integers. See How to convert decimal to hex in JavaScript?
console.log(getHexColor(-16731137)); // light blue
console.log(getHexColor(-1218518)); // orange
function getHexColor(number){
return "#"+((number)>>>0).toString(16).slice(-6);
}
Post a Comment for "Java Color Integer To RGB String In JavaScript"