So this is my code, my input fields are supposed to have decimal numbers, that part does work.
I need to convert the text showing into a decimal as well, not a string, so that I can later add a part of the code that increases the number that was written at first. I’ve tried a lot of tricks, but none seem to work. Is there a way to convert the Text to a decimal? P.S I am using System
public class GameManager : MonoBehaviour {
public InputField Jackpot1;
public Text Jack1;
public InputField Jackpot2;
public Text Jack2;
public InputField Jackpot3;
public Text Jack3;
public void CopyText()
{
Jack1.text = Jackpot1.text;
Jack2.text = Jackpot2.text;
Jack3.text = Jackpot3.text;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Convert.ToDecimal (Jack1);
}
C#'s datatypes have a built in function that allows you to parse string data into int’s, float’s and double’s. Simply check out the Parse() and TryParse() methods.
These methods allow you to convert a string into a number type. Parse will attempt to parse the string and if it fails it will throw a FormatException. If you want to perform some simple exception handling then TryParse will allow you test if the parse was successful.