Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
This question was closed Aug 02, 2017 at 01:13 AM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by mediamavrick · Mar 08, 2014 at 03:07 AM · floatdecimal

How do I get rid of the numbers after the decimal?

I have this piece of code that does a countdown and it works fine, but it shows the numbers 5 places after the decimal does anyone know how I can get rid of this? I wouldnt even mind it just showing the numbers 2 places after the decimal. More preferably I would like the numbers after the decimal gone though. here is my code:

 var timeLv1 : GUIText;
  var timer : float = 30.000000000;
  var outOfTime : boolean = false;
   
 function level1 () {
    
     timer -= Time.deltaTime;
     timeLv1.text= "time: " + timer;
     if(timer <= 0){
     
     timer = 0;
     outOfTime = true; 
     }
  
     }

 function Update () {
 
 if(Application.loadedLevelName == "gameLvl1"){
 
 level1();
 if(outOfTime){
 
 GameOver();
 }
 }
Comment
Comments Locked
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

  • Sort: 
avatar image
8
Best Answer

Answer by Eric5h5 · Mar 08, 2014 at 04:08 AM

 timeLv1.text= "time: " + timer.ToString("f0");
Comment
Comments Locked · Show 2 · 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 DigitalCandy · Dec 01, 2016 at 12:17 PM 0
Share

This is by far the simplest, most elegant solution

avatar image CelticKnight · Aug 02, 2017 at 12:37 AM 0
Share

Thanks greatly for that!

avatar image
0

Answer by Pecek · Mar 08, 2014 at 03:12 AM

Maybe there is a builtin function for this, but it would probably do exactly as this one: http://answers.unity3d.com/questions/197196/round-to-decimals.html

Comment
Comments Locked · Show 4 · 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 mediamavrick · Mar 08, 2014 at 03:45 AM 0
Share

This does not seem to work for. It keeps saying $$anonymous$$athf is not apart of float

avatar image Pecek · Mar 08, 2014 at 03:57 AM 0
Share

I just tested it and works fine here, can you please post your snippet?

avatar image mediamavrick · Mar 08, 2014 at 04:01 AM 0
Share

@Pecek Here is What I have. I think I might just be inputing the code wrong. Can I see what you put?

  var timeLv1 : GUIText;
  var timer : float = 30.000000000;
  var outOfTime : boolean = false;
  
 function level1 () {
  
     timer -= Time.deltaTime.$$anonymous$$athf.Round(randomNumber*100.0) /100.0;
     timeLv1.text= "time: " + timer;
     if(timer <= 0){
  
     timer = 0;
     outOfTime = true; 
     }
  
     }
 
avatar image Pecek · Mar 08, 2014 at 04:20 AM 0
Share

timer -= Time.deltaTime.$$anonymous$$athf.Round(randomNumber*100.0) /100.0;

this line can't be right, try using this ins$$anonymous$$d

timer -= $$anonymous$$athf.Round(Time.deltaTime *100.0) /100.0;

Also you can use Eric5h5's solution, but if you want to use it again as a number you'll have to convert it back(which looks a bit overkill for me)

Follow this Question

Answers Answers and Comments

24 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

Related Questions

Rotation Values Garbled When Set By Code 2 Answers

Precision decimal data type 2 Answers

How do you convert Random.Range to two decimal places? 1 Answer

Unity/C# ignores decimal after it reach some value 1 Answer

Does parseFloat depend on the OS? 2 Answers


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