Apologies for sloppy work and probably a poor grasp of fundamentals.
I have a (likely primitive) way to convert the ever increasing number values of my enemy hp into a string format to display in game. (K for thousands, M for millions, B for billions etc)
if (target_healthmax >= 1000)
{
if (target_healthmax >= 1000000000)
{
enemy_hp_text.text = "Health: " + (target_healthcur * 0.000000001f).ToString("#.00") + "/" + (target_healthmax * 0.000000001f).ToString("#.00") + "B";
}
else
{
if (target_healthmax >= 1000000)
{
enemy_hp_text.text = "Health: " + (target_healthcur * 0.000001f).ToString("#.00") + "/" + (target_healthmax * 0.000001f).ToString("#.00") + "M";
}
else
{
enemy_hp_text.text = "Health: " + (target_healthcur * 0.001f).ToString("#.00") + "/" + (target_healthmax * 0.001f).ToString("#.00") + "K";
}
}
}
else
{
enemy_hp_text.text = "Health: " + target_healthcur + "/" + target_healthmax;
}
but I stopped here after I noticed that although I could convert long numbers I would eventually hit a number too large to handle such as "-2.147484e+09" in my editor, and it would stop working.
I am using floats currently, is there a different type of variable that handles this easily? if not, what is an efficient way of solving this?
Would it be efficient to convert every new factor of 100 to a new variable and only handle the highest valued variable? eg
if num >= 1000, k += 1, num = 0;
if k>= 1000, m += 1, k = 0;
...
(Please feel free to let me know anything about my post I may need to amend, I am new here)