Using a stat In Post Damage Evaluation Math

Code:
<Post-Damage Eval>
var bonusStateRate = 0.20 + (user.luk / 300);
if (Math.random() < bonusStateRate && target.elementRate(1) > 1) user.addState(7);
</Post-Damage Eval>

In my project, I'm using this post damage evaluation to award a bonus state if you hit an enemy's weakness and if a random chance passes. But I would like to use the luck stat of said actor in the evaluation so that the luck stat has a bit more use in the game. The actor's luck gets taken and divided by a large number so it's added as a minor modifier to the bonus state rate. This code works, but I'm wondering if there's any issues with floating numbers?

As an example, if var bonusStateRate was 0.20 + (user.luk / 300), where the users luck was 44, google says the answer to 44 / 300 is 0.14666666666.
Is that still a smaller number than 0.80? Will a floating number give a pass when it shouldn't have been a pass?

Additionally:
I'm also curious how to have it add the bonus state if the hit was critical? Would that be it's own "if" line?
There's no issues with floating numbers. The code you wrote should work as intended.

If you want it so that a critical hit will always add the state to the user, you can use an 'or' (which is || in js) in the if line:

Code:
if ((Math.random() < bonusStateRate && target.elementRate(1) > 1) || target.result().critical) user.addState(7);

If you want it so that the state is always added on a critical hit given that the weakness condition still has to be met, just combine the 'or' statement with the random chance check instead using parentheses:

Code:
if ((Math.random() < bonusStateRate || target.result().critical) && target.elementRate(1) > 1) user.addState(7);
Thanks for your help once again, Naveed!
Quick question: can you use 'or' multiple times?

I.E like so:
Code:
<Post-Damage Eval>
if ((condition 1) || (condition 2) || (condition 3) || (etc.)) RESULT;
</Post-Damage Eval>
Yes you can. The if statement will pass if any of the conditions is true.

Original thread: https://forums.rpgmakerweb.com/threads/using-a-stat-in-post-damage-evaluation-math.83218/