Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 /
avatar image
0
Question by jsheehan22 · Apr 27, 2020 at 02:39 AM · counter

How do I get very high numbers to register within Unity?

I'm making a game where you climb stairs and earn points with each step - kind of like a clicker. I have it coded so that new dialogue appears when your score reaches specific amounts (Your score goes up using "onTriggerEnter")

So far it's worked flawlessly, but towards the end, the score gets really high, so Unity abbreviates the numbers to 1e+08. The last dialogue that appears is at the number 100,000,000, which it abbreviates to 1e+08, but when I try to get the dialogue to change at let's say, 100,001,000 (which it abbreviates to1.00001e+08), the new dialogue does not appear.

I think this is a Unity software question. as I've also noticed that if I change my score manually while the game is running in Unity, it turns 99,999,999 into 100,000,000 automatically.

Thanks!

If this helps:

{

 public float currentMoney;
 public float step = 100;
   

 public TextMeshProUGUI moneyText;

  void Update()
 {
     UpdateUI();
 }

 // Update is called once per frame
 void UpdateUI()
 {
     moneyText.text = "Money: $" + currentMoney.ToString("N0") + ",000";
 }

 public void IncreaseScore()
 {
     currentMoney = (currentMoney + step);
         UpdateUI();
 }

  

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Apr 27, 2020 at 03:14 AM

Well, this is not really a Unity thing that's just how floating point numbers work. I recommend to have a look at my answer over here where I've posted a table to show how the precision changes with increasing numbers. Also this interactive Floating point converter is quite handy to better understand the underlaying structure.


Though apart from that I really recommend spending those 10 minutes to watch this Computerphile video on floating point numbers


Depending on your usecase if you only need to deal with whole numbers you might want to just use a long (64bit number). If a long isn't enough you can use the BigInteger class. Though that class is orders of magnitude slower than primitive types like int or long. Though for a clicker game using BigInteger isn't really a problem.

Comment
Add comment · Show 1 · 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 jsheehan22 · Apr 27, 2020 at 03:40 AM 0
Share

Ahh, I'm not used to dealing with such big numbers, thanks for the links, I'm checking them out now!

avatar image
1

Answer by KiTS0 · Apr 27, 2020 at 03:19 AM

Here's an example of what I'm thinking of.


This is just to resolve the display of the counted stairs.


 using System;
 using UnityEngine;
 using UnityEngine.UI;
 
 
 
 public class CountStairs : MonoBehaviour 
 {
 
     
     public Text stairCountTextField;
     void Start() 
     {
         //A UI > Text GameObject named CountToText //Gets Text component inside of CountToText
         stairCountTextField = GameObject.Find("CountToText").GetComponent<Text>();
 
         //Manual assignmnet into the text field.
         //stairCountTextField.text = "test.";
         
     }
     
     //int has a limit of 2147483647
     //long has a limit of 9223372036854775807 
     //See more at https://www.tutorialsteacher.com/csharp/csharp-data-types
     public long step;
     void Update() 
     {
 
         stairCountTextField.text = Convert.ToString(step);
             
     }
 
 
 }
 


Comment
Add comment · Show 1 · 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 jsheehan22 · Apr 27, 2020 at 03:40 AM 1
Share

I changed "float" to "long" and it seems to have worked!

Thanks so much, I'll take a look at that tutorial!

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

126 People are following this question.

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

Related Questions

Timer Runtime Problem 2 Answers

Can anyone help ?? Timer and gui 0 Answers

pickup counter and timer help 0 Answers

How can I get an accurate gameObject count within a frame? 1 Answer

My orb and gem counter are counting simultaneously? 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