Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Thatmexicanuzer · Nov 19, 2016 at 01:20 AM · textdecimal

UI Text to Decimal. How?

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);

 }


}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Cepheid · Nov 19, 2016 at 01:28 AM

@Thatmexicanuzer

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.

Double.TryParse Example - MSDN Docs

Float.Parse Example - MSDN Docs

Int.TryParse - DotNetPerls

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by MusicKing7 · Nov 19, 2016 at 02:35 AM

 float.Parse("Text name".text)

This turns the text from your text component into a float.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by EvalDaemon · Jan 17 at 04:25 AM

How the hell does these WRONG solutions come up at the top of the search.

It's

 string s = "-3.14";
 float f = 0f;
 if (float.TryParse(s, out f))
  {
  Debug.Log("results= "  + f );
  }
 else Debug.Log("Failed to Parse.");



The first answer I guess isn't WRONG, but is referencing .NET6 and has broken links. The second isn't really much of an answer.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI Text is Gigantic 2 Answers

Blurry text on InputField 1 Answer

Changing text through a cursor hover trigger 0 Answers

How To Load TTF Font From External File 0 Answers

How to link up instantiated text in list to allow buttons to adjust number shown, c# 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges