Search Unity

Decimal update

Discussion in 'Editor & General Support' started by tiago7727, Sep 1, 2015.

  1. tiago7727

    tiago7727

    Joined:
    Aug 24, 2015
    Posts:
    12
    So i had this line Golddisplay.text = Euro.ToString("f0"); but i updated to this one
    Golddisplay.text = currencyconverter.Instance.getcurrencyintostring (Euro, false, false); because i needed to converte the currency,but now it shows the decimal numbers and i cant seem to fix it can you guys help?
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    you can still "ToString" a string. Hell, you could say "myString.ToString().ToString().ToString();"


    So to solve your problem, change
    "Golddisplay.text = currencyconverter.Instance.getcurrencyintostring (Euro, false, false);"

    to
    "Golddisplay.text = currencyconverter.Instance.getcurrencyintostring (Euro, false, false).ToString("f0");"
     
  3. tiago7727

    tiago7727

    Joined:
    Aug 24, 2015
    Posts:
    12
    i cant Nova Imagem de Mapa de Bits.png
     
  4. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Strange... try this instead.
    Code (CSharp):
    1. string tmpString = currencyconverter.Instance.getcurrencyintostring (Euro, false, false);
    2.  
    3. // This will remove every character after (and including) the decimal point
    4. Golddisplay.text = tmpString.Substring (0, tmpString.IndexOf ("."));
     
  5. tiago7727

    tiago7727

    Joined:
    Aug 24, 2015
    Posts:
    12
    it works until it reachs 1k...and i just realized my problem it was in the currency converter
    public string getcurrencyintostring( float valuetoconvert, bool currencypersec,bool currencyperclick){
    string converted;
    if (valuetoconvert >= 1000000) {
    converted = (valuetoconvert / 1000000f).ToString ("f0") + "Mil";
    } else if (valuetoconvert >= 1000) {
    converted = (valuetoconvert / 1000f).ToString ("f1") + "K";
    } else {
    converted = "" + valuetoconvert ;
    }
    if (currencypersec == true) {
    converted = converted + "Euro/sec" ;
    }
    if (currencyperclick == true) {
    converted = converted + "Euro/click";
    }
    return converted;
    }
    and then i put converted = "" + valuetoconvert.toString("f0") ;
    I didnt realize the proble was in the converter in itself because the display was the one messing up,thanks for the help anyway, few people would try to help so much ur a boss and deserve a folow
     
    Last edited: Sep 5, 2015