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 El__Nacho · Oct 03, 2015 at 03:48 PM · c#textcalculationdoubletostring

Calculation with values over 2 billion

I want to display the value from a double variable with an ui text and I'm using only double values. But after the calculations it displays somtimes negative values. Here is my code, but only the declaration and last method are relevant for my problem. It seems the calculated value is converted into an int anywhere but I can't find the reason.


baseProduction=2000000000
Level= between 1 and 500
[code language="c#"] using UnityEngine; using UnityEngine.UI; using System.Collections;

public class ProductionScr : MonoBehaviour {

 public int baseProduction;
 public float baseDuration;
 public int baseCost;

 public int environmentMalus;
 public int environment;

 public double realProduction;
 public float realDuration;
 public long realCost;
 public int realEnvironmentMalus;




 public float remainingTime;
 public bool manager;
 public bool produce;
 private bool process;
 public int Level;
 public int productionID;


 public GameObject valueHolder;
 public Image processBalken;
 public Text profit;
 public Text unit;





 void Start(){
     UpdateStats ();

     produce = false;
     remainingTime = realDuration;
 }


 //increases Level
 public void IncreaseLevel(){
     Level += 1;
     //valueHolder.GetComponent<ValueHolder> ().environment += environmentMalus;
     UpdateStats ();
     valueHolder.GetComponent<ValueHolder> ().UpdateAllStats (productionID);

 }

 public void Produce(){
     if (process == false&& manager==false) {
         StartCoroutine (Process ());
     }
 }



 void Update(){
     if (process==false && manager==true){
         StartCoroutine (Process ());
     }
     remainingTime -= Time.smoothDeltaTime;
 }


 IEnumerator Process(){
     process = true;
     while (true) {
         yield return new WaitForSeconds (0.001f);
         processBalken.rectTransform.sizeDelta = new Vector2(((realDuration - remainingTime) / realDuration)*368*2-370,1);
         if (remainingTime <= 0) {
         

     
             remainingTime = realDuration;
             Debug.Log ("Finished");
             produce = false;
             process = false;
             valueHolder.GetComponent<ValueHolder> ().balance += realProduction;
             yield return null;
         }

     }
 }


 public void UpdateStats (){

     //Change Profit
     environment = (valueHolder.GetComponent<ValueHolder> ().environment);
     if (environment != 0) {    
         
         realProduction =System.Convert.ToDouble (baseProduction * Level * (1 - Mathf.Pow (1.000460523f,environment) / 100)); //Berechnet Produktion aus Level, Basis und ValueHolder.environment
     } else {
         realProduction =System.Convert.ToDouble (baseProduction * Level);
     }

     if (realProduction < 1000000) {
         profit.text = realProduction.ToString ();
         unit.text = "€";
     }
     else if (realProduction >= 1000000 && realProduction < 1000000000D) {
         profit.text = (realProduction / 1000000).ToString();
         unit.text = "Million €";
     } else if (realProduction >= (double)1000000000D && realProduction < (double)1000000000000D) {
         profit.text = (realProduction / (double)1000000000D).ToString();
         unit.text = "Billion €";
     } else if (realProduction >= (double)1000000000000D && realProduction < (double)1000000000000000D) {
         profit.text = ((realProduction / (double)1000000000000D)).ToString();
         unit.text = "Trillion €";
     }

     //Change Cost
     realCost = Mathf.RoundToInt(System.Convert.ToSingle( baseCost * Level * Level* 3));

         
     //Change Duration
     realDuration =System.Convert.ToSingle( baseDuration / System.Math.Pow(2,Mathf.Floor (Level / 50)));

     //Change Environmentmalus
     realEnvironmentMalus = environmentMalus * Level;
     //applies Environmentmalus
     valueHolder.GetComponent<ValueHolder> ().environmentInfluence[productionID] = realEnvironmentMalus;


 }

} [/code]

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by El__Nacho · Oct 03, 2015 at 03:58 PM

Oh I've found my problem xD the varibale baseProduction has to by of type double instead of int.

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

29 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

Related Questions

Calculate arithmetic problem from text 1 Answer

Removing an item from Inventory and updating item count on HUD 0 Answers

text not changing in build for android unity 1 Answer

Countdown Timer 2 Answers

(C#) How can I make a rich text autotyper for an rpg dialogue box? 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