get integer as percent

Hi,

I’m trying to calculate the percentage of how much ammo is left in the clip per magazine size of each gun. The division is giving me a result of 10 and then multipliying is 1000. If they were floats to begin with it wouldn’t be a problem but is there a way to do this with Integers?

I don’t think it would be any different if they were floats.
20 is effectively 1000% of 2.
Try to reverse the inputs ? 2 of 20 should result in 10%, which I assume is what you’re looking for, unless I’m reading these variables wrong.

I think OP wants this?

image

This would give you 10, as in 10 percent. But you’re losing precision, not sure if important here. Besides that, UE expects percentage in the 0-1 range so you’re setting yourself up for another potential conversion further down the lane.


Why not stick with floats?

1 Like

Sadly all my ammo variables are set as Integers but I managed to kinda sort most of the problem. Essentially I am just turning the ammo text red to signify that the ammo is low (less than 20% or per the weapons “low” threshold)

BP for reference

I would however like the reserve ammo threshold to be different to the current ammo threshold, I can only think to make 2 seperate functions for this but would prefer it in one as in the Check is Ammo Type Low function, any ideas?

Ammo should be int, cast to float to calculate percentage easily or use the multi posted above:

image

Apologies for bluntness but this seems like creating issues where none exist :person_shrugging:

reserve ammo threshold

Sadly, I do not understand what is needed here. It might be me, though.

1 Like

thats ok, I am trying to overcomplicate things :sweat_smile: I used to write lines and lines of bp that could have been compacted so now I’m just trying my best to keep things short. It works as is so not a major issue just preference :slight_smile:

1 Like