Ich benutze Unity, um ein "Incremental Game" auch als "Idle Game" bekannt zu machen, und ich versuche, große Zahlen zu formatieren. Zum Beispiel, wenn gold
1000 oder mehr zu sagen bekommt, wird es als Gold: 1k
anstelle von Gold: 1000
angezeigt.Formatieren von großen Zahlen in C#
using UnityEngine;
using System.Collections;
public class Click : MonoBehaviour {
public UnityEngine.UI.Text GoldDisplay;
public UnityEngine.UI.Text GPC;
public double gold = 0.0;
public int gpc = 1;
void Update(){
GoldDisplay.text = "Gold: " + gold.ToString ("#,#");
//Following is attempt at changing 10,000,000 to 10.0M
if (gold >= 10000000) {
GoldDisplay.text = "Gold: " + gold.ToString ("#,#M");
}
GPC.text = "GPC: " + gpc;
}
public void Clicked(){
gold += gpc;
}
}
Ich habe andere Beispiele versucht, während der Suche online, das ist, wo gold.ToString ("#,#");
herkam, aber keiner von ihnen arbeitete.
'gold.ToString' ein Ergebnis zu wissen gibt, nicht ändern es nicht' Gold'. Du musst etwas wie 'GoldDisplay.text = "Gold:" + gold.ToString ("#, #"); ' – Blorgbeard
Wie groß wird diese Goldzahl? Sag Quadrillionen? – Zze
Aber du wirst Probleme mit 'int' für ein leeres Spiel haben. Der Maximalwert beträgt 2 Milliarden. – Blorgbeard