#Reduce the amount of decimals with ToString()

1 messages · Page 1 of 1 (latest)

steel raven
#

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?

brittle marlin
#
  1. an idle game
  2. 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

dire solstice
#

you should use a custom number class for incremental games imo

steel raven
brittle marlin
#
    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

steel raven
#

By the way, when I make a thread, I expect to be left alone in it, with the person who requires help.

dire solstice
#

no, not custom double class 😛 custom 'number' class

#

oh ok, sry

steel raven
#

.ToString("F2"); at the end

brittle marlin
brittle marlin
#

to be exact\

#

i dotn want to change the wrong one

steel raven
#

balancestr = Math.Round(Convert.ToDecimal(balancestr), 2).ToString();
balancestr = Math.Round(Convert.ToDecimal(balancestr), 2).ToString("F2");

brittle marlin
#

balancestr = Math.Round(Convert.ToDecimal(balancestr), 2).ToString();

#

ok

#

ill try it now

#

it still doesnt work

#

K

#

M

steel raven
#

wow bot

brittle marlin
#

😭

#

got it to work

#

if (!BalanceText.TryTranslate(balancenum, out var balancestr))
{
balancestr = balancenum.ToString("F2");
}

steel raven
#

ah

#

that's the spot

#

There's more flexibility with string.Format()

brittle marlin
#

ah

#

but thank you so much for your help

steel raven
#

You're welcome.
Now, was the a different issue also?

brittle marlin
#

there are no issues that i can think of

#

<33

steel raven
#

Alright. Have a nice day 👍