- Home /
Why is the currency converter not converting money into (k) = (thousand) or (M) = (million)?
SO when I reach $1000 in my idle game, i want to to turn into $1K, same with the millions. But there are no errors and it doesnt convert? here is the code. using UnityEngine; using System.Collections;
public class CurrencyConverter : MonoBehaviour {
private static CurrencyConverter instance;
public static CurrencyConverter Instance{
get{
return instance;
}
}
void awake(){
CreateIntance();
}
void CreateIntance(){
if (instance == null) {
instance = this;
}
}
public string GetCurrencyIntoString(float valueToConvert, bool currencyPerSec, bool currencyPerClick){
string converted;
if (valueToConvert >= 1000000) {
converted = (valueToConvert / 1000000f).ToString ("F3") + " M";
} else if (valueToConvert >= 1000) {
converted = (valueToConvert / 1000f).ToString ("F3") + " K";
} else {
converted = "" + valueToConvert;
}
if (currencyPerClick == true) {
converted = converted + " tpc";
}
return converted;
}
}
IS there something wrong in the code? Plz reply with the best feedback as possible, thanks.
what result do you get? p.s. this method can be a static one without the need of the class being instantiated.
i get nothing just the number like 2742 ins$$anonymous$$d of 2.74k
Answer by hexagonius · Sep 19, 2015 at 10:06 PM
the code looks absolutely right. if the tostring format was wrong then at least the division should take place.have you tried setting break points Rio make absolutely sure THIS code is called and which value is generated where?
@hexagonius the total amount of money, moneyperclick, and monetpersecond
and do u $$anonymous$$d checking out some of my other question, thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220612033537im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rounding 235000 to 235? 2 Answers
Is Encrypted Playerprefs Safe Enough For Virtual Currency? 2 Answers
How to implement a store into mobile game 0 Answers
Help with GUI Currency 1 Answer