Stelrex
(Stelrex)
February 2, 2019, 1:14am
#1
I’m trying to print the BackgroundColor3 of a Frame, but it prints out in a 0-1 range instead of 0-255 like you’d expect.
My code is
print(script.Parent.BackgroundColor3)
Really short post but that’s my issue. If you know why this happens (Maybe it’s intended?) let me know.
Stelrex
(Stelrex)
February 2, 2019, 1:16am
#4
Say the decimal is .3333, multiplying that by 255 is 84.9915.
How would I round that?
NPh_rd
(NPh_rd)
February 2, 2019, 1:16am
#5
round is
math.floor(x * 10^decimals + 0.5)/10^decimals
If you wanted an integer, decimals
would be 0
OverHash
(OverHash)
February 2, 2019, 1:16am
#6
You can use string.format(‘%0.2f’, number) or a few other methods
kingdom5
(kingdom5)
February 2, 2019, 1:18am
#7
OverHash:
BackgroundColor3
you cannot multiple a color3? you need to get the r,g,b values then multiply them.
3 Likes
XAXA
(XAXA)
February 2, 2019, 1:21am
#10
local color = script.Parent.BackgroundColor3
local r, g, b = color.r, color.g, color.b
-- %0.f : Round and truncate the decimal portion of each number.
local str = string.format("%0.f, %0.f, %0.f", r*255, g*255, b*255)
print(str) -- `85, 85, 85` if color was something like .3333, .3333, .3333
12 Likes
Why are you using %0.f
over %d
; is there a specific reason?
XAXA
(XAXA)
February 2, 2019, 11:10am
#13
%d rounds down always. 1.9999 gets round down to 1.
2 Likes