if statement not wokring when detecting color

I am trying to do a if statement is red equals 0.90196078431373 but it does not work.

If i do print(red) it shows the numbers

local ragdogLib = require "ragdogLib"; function randomcolor() local colors = { "#e67e22","#e74c3c" ,"#f1c40f","#1abc9c","#8e44ad" } local finalcolor = colors[math.random(1, 5)]

local function addnewobject()     local bombstartnew = display.newRect( startingpoint, -340, 50, 50)  red, green, blue = ragdogLib.convertHexToRGB(randomcolor())     bombstartnew:setFillColor(red,green,blue); if (red ==  "0.90196078431373") then   print("color") end

timer.performWithDelay( 500, addnewobject, 0 )

While it is possible to land exactly on certain decimal values, it’s a total fluke if you manage to do so with, say, something returned by a calculator. Lua will do the best it can and round it to an exactly representable number nearby.

What you would be better off doing is to compare against a small tolerance, e.g. as

if math.abs(red - 0.90196078431373) \< .001 then -- round to nearest thousandth

or

if (red - 0.90196078431373)^2 \< .000001 then -- round to nearest thousandth (squared)

Also, it looks like you’re checking for a string, and not a value. I’d suggest implementing Starcrunch’s edit, and remember to leave if the quotes from the red value check.

While it is possible to land exactly on certain decimal values, it’s a total fluke if you manage to do so with, say, something returned by a calculator. Lua will do the best it can and round it to an exactly representable number nearby.

What you would be better off doing is to compare against a small tolerance, e.g. as

if math.abs(red - 0.90196078431373) \< .001 then -- round to nearest thousandth

or

if (red - 0.90196078431373)^2 \< .000001 then -- round to nearest thousandth (squared)

Also, it looks like you’re checking for a string, and not a value. I’d suggest implementing Starcrunch’s edit, and remember to leave if the quotes from the red value check.