0
votes

I have following set of RGB points which I want to convert as a color Code.

"colors": 
[
   [ 1.00, 0.00, 0.00 ],
   [ 0.71, 0.71, 0.00 ],
   [ 0.00, 1.00, 0.00 ],
   [ 0.00, 0.71, 0.71 ],
]

I want something like ##00bfff. If I would have points something like (247, 255, 164), I can use below function and convert but my points are in decimal values.

function RGBToHex(rgb: number[]) {
    let r = rgb[0].toString(16),
    g = rgb[1].toString(16),
    b = rgb[2].toString(16);
    if (r.length == 1) r = "0" + r;
    if (g.length == 1) g = "0" + g;
    if (b.length == 1) b = "0" + b;
    return "#" + r + g + b;
}
Which language? (please do not forget to put it into the tag). Often you should convert the numbers to integers, or tell the "toString" to use only the integer parts. But it depends on languageGiacomo Catenazzi
@GiacomoCatenazzi Thanks for the input. Its in JavaScript.coder91