I am looking to use a piece of code to take an extremely long number and convert it to decimal equivalent + short scale. (i.e. 120100000000 would be 120.1 Billion)
I am doing this with two separate scripts but this can be condensed into a single one. I am trying to look for a recurring process instead of the massive amount of if statements currently running in the script. This is being done with an external array in Unity that holds the strings for short scale. (billion,trillion, etc)
Trying to find a recurring model that will look for the length, and attach it to the appropriate array object.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class amountText : MonoBehaviour {
public Text text;
public Text numberPref;
public string[] values;
public static float number = 1000f;
private float numberLength;
private float remainder;
private float increaseAmount = 5000f;
void Start () {
text = GetComponent <Text>();
}
void Update () {
text.text = Mathf.RoundToInt(number).ToString();
numberLength = Mathf.RoundToInt(number).ToString().Length;
if(numberLength <9) {
text.text = Mathf.RountToInt(number).ToString();
numberPref.text = (" ");
}
if(numberLength > 9 && numberLength =< 12) {
text.text = number/1E-9;
numberPref.text = (values[0]);
}
if(numberLength > 12 && numberLength =< 15) {
text.text = number/1E-12;
numberPref.text = (values[1]);
}
if(numberLength > 15 && numberLength =< 18) {
text.text = number/1E-15;
numberPref.text = (values[2]);
}
}
}