A way to write large numeric literals in C #

I have a way like this:

Prefix GetPrefix(decimal value)
{
    if(value > 11000000000000000000)
        return Prefix.CosmicBig;
    if(value > 1000000000000000)
        return Prefix.ReallyBig;
    if(value > 3000000000000)
        return Prefix.Big;
    if(value > 50000000)
        return Prefix.Okay;
    if(value > 750000)
        return Prefix.MostlyNormal;
    if(value > 750000)
        return Prefix.SoSo;
    if(value > 750)
        return Prefix.Small;
    return Prefix.MiserablySmall;
}

The exact values ​​are not important. The important thing is that they sometimes change (prefixes are used for drawing, and some text areas are resized in development). I am looking for a way to write these literals in a way that is easy to read by the person modifying it, not counting all the zeros. The separator will be enjoyable. I was thinking of writing 11 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000, but it was hardly more manageable. The use is a Math.Pow()little better, but I am not comfortable using such calculations to determine constants.

+5
source share
2 answers

You can enter extension methods for int:

750.Thousand();
5.Million();
100.Billion();

The implementation of these methods is simple:

public static int Thousand(this int value)
{
    return value * 1000;
}

public static int Million(this int value)
{
    return value.Thousand() * 1000;
}

// etc.

:

public static long Billion(this int value)
{
    return value.Million() * 1000;
}

, , .

, :

100.Billion() + 30.Thousand() + 300 // == 100,000,030,300

, , :

100.Billion(30.Thousand(300))

, , , .

, :

public static long Billion(this int value, long add)
{
    return value.Million() * 1000 + add;
}

: . . .

+15

11000000000000000000 11e18. m, , , 11e18m.

+19

All Articles