Hey everyone,
I have a script for rounding floats, but it’s getting very long, the more floats I use in my game. Does anyone probably know how to write this piece of code shorter and easier or an exemple on how to write one piece of code that is able to round all these floats?
if (mS.score < 1000.0) { mS.scoreText.text = Mathf.Round(mS.score) + ""; } else
if (mS.score < 1000000.0) { mS.scoreText.text = Mathf.Round(mS.score / 1000) + "K"; } else
if (mS.score < 1000000000.0) { mS.scoreText.text = Mathf.Round(mS.score / 1000000) + "M"; }
if (mS.money < 1000.0) { mS.moneyText.text = Mathf.Round(mS.money * 100) / 100 + ""; } else
if (mS.money < 1000000.0) { mS.moneyText.text = Mathf.Round(mS.money / 1000 * 100) / 100 + "K"; } else
if (mS.money < 1000000000.0) { mS.moneyText.text = Mathf.Round(mS.money / 1000000 * 100) / 100 + "M"; }
if (mS.gems < 1000.0) { mS.gemsText.text = Mathf.Round(mS.gems) + ""; } else
if (mS.gems < 1000000.0) { mS.gemsText.text = Mathf.Round(mS.gems / 1000) + "K"; } else
if (mS.gems < 1000000000.0) { mS.gemsText.text = Mathf.Round(mS.gems / 1000000) + "M"; }
if (mS.mPs < 1000.0) { mS.mPsText.text = Mathf.Round(mS.mPs * 100) / 100 + ""; } else
if (mS.mPs < 1000000.0) { mS.mPsText.text = Mathf.Round(mS.mPs / 1000 * 100) / 100 + "K"; } else
if (mS.mPs < 1000000000.0) { mS.mPsText.text = Mathf.Round(mS.mPs / 1000000 * 100) / 100 + "M"; }