How do I convert an RGB color value to a decimal color value?

Lets say I had the RGB color
r=255, g=0, b=0
How do I convert this RGB color into a decimal/integer color?
The correct color for this is ‘16711680’ (if i’m correct) but I need to know how to calculate it.

Any answers?

I found a good website that works. Here you go:

Using a script to do it would be very long.
Have a good day!

I found the website, however for what I’m using it for, I need to actually calculate the RGB into the decimal color. (aka code)

Into code? I am so confused right now. So you need the formula to calculate it?

Yes. I need the formula to calculate it in Lua. I found a JS example but I didn’t understand it.

Could you send me the JS example? I have some experience in JS from when I was in college.

I have this

If you want this in a lua script, I don’t think you can find it anywhere unless it’s made.

Easiest way is to convert it to hex then to decimal. It’s relatively simple as well.

local r = 255
local g = 0
local b = 0
local rh = string.format("%02x", r) -- minimum returned numbers 2, left padded with 0's see https://developer.roblox.com/en-us/articles/Format-String
local gh = string.format("%02x", g)
local bh = string.format("%02x", b)
local hex = "0x"..rh..gh..bh
local dec = tonumber(hex)
print("Vals: " .. r .. ", " .. g .. ", " .. b)
print("Hex: " .. hex)
print("Decimal: " .. dec)

Pretty sure you can one line it too string.format("%02x%02x%02x", r, g, b)

2 Likes

I had this in mind but didn’t know if it would secure it.

Thanks, thisll help a lot! Also thanks @x1_ee, you helped too!