#Reduce the amount of decimals with ToString()
1 messages · Page 1 of 1 (latest)
Let's take this from the top.
You have a game. There's money. What kind of game is it?
Are you already using BigDouble, or is that only in this script?
- an idle game
- i use bigdouble all throughout the project as idle games need huge numbers when players progress
balancenum2 = balancenum;
balancestr2 = balancenum2.ToString("F2");
balancenum3 = BigDouble.Parse(balancestr2);```
this is a temporary solution
you should use a custom number class for incremental games imo
That's precisely what he's doing.
private static readonly Dictionary<BigDouble, string> translations = new()
{
{ 1_000_000_000_000_000_000, "QUIN" },
{ 1_000_000_000_000_000, "QDR" },
{ 1_000_000_000_000, "T" },
{ 1_000_000_000, "B" },
{ 1_000_000, "M" },
{ 1_000, "K" }
};
private static bool TryTranslate(BigDouble balancenum, out string? balancestr)
{
balancestr = null;
foreach (var translationPair in BalanceText.translations)
{
var outputUnparsed = balancenum / translationPair.Key;
if (outputUnparsed < 1)
{
continue;
}
balancestr = outputUnparsed.ToString();
balancestr = Math.Round(Convert.ToDecimal(balancestr), 2).ToString();
balancestr += translationPair.Value;
break;
}
return !string.IsNullOrEmpty(balancestr);
}```
i usethis to format to million
etc
By the way, when I make a thread, I expect to be left alone in it, with the person who requires help.
Perhaps what you want can be achieved by simply editing the second last line before the break;
.ToString("F2"); at the end
can you copy paste the line
to be exact\
i dotn want to change the wrong one
balancestr = Math.Round(Convert.ToDecimal(balancestr), 2).ToString();
balancestr = Math.Round(Convert.ToDecimal(balancestr), 2).ToString("F2");
balancestr = Math.Round(Convert.ToDecimal(balancestr), 2).ToString();
ok
ill try it now
it still doesnt work
K
M
wow bot
😭
got it to work
if (!BalanceText.TryTranslate(balancenum, out var balancestr))
{
balancestr = balancenum.ToString("F2");
}
You're welcome.
Now, was the a different issue also?
Alright. Have a nice day 👍