I want to compare 2 values based on which I get the color for my legend. But unfortunately I cannot use ceil, floor or round the values as it will effect my result.
I have following color table with first value as point and rest 3 values are r g b values.
Basically I get point from backend which ca be 0.4607441262895224, 0.5500956769649571 and so on. I need to compare the point with first value in color table and give corresponding color. But I am facing issue in comparing , as currently I have given to Fixed(2) but it is not recommended.
"colors": [
[ 0.00, 255, 13, 186 ],
[ 0.25, 254, 4, 135 ],
[ 0.50, 73, 255, 35 ],
[ 0.75, 185, 116, 255 ],
[ 1.00, 32, 50, 255 ]
]
// main logic
const test = arraySet.find((ele) => {
// point is dynamic
const point = 0.388920938
// I cannot use toFixed(2) here, which need to be changed
// ele[0] is the first value in array 0.00, 0.25, 0.50 and so on
return point.toFixed(2) == ele[0].toFixed(2);}
);