error at big numbers

I have this code and I had to put e+ because the number was very large and when I put it that way, sometimes 1000 Billion comes out and other times 1 Billion Billion
translated by translategoogle

//Dinero en Texto
        if (DineroTotal < 1000)
        {
            textDinero = DineroTotal.ToString("F");
        }
        else if (DineroTotal > 1e+33)
        {
            textDinero = (DineroTotal / 1e+33).ToString("F") + " mil Quintillones";
        }
        else if (DineroTotal > 1e+30)
        {
            textDinero = (DineroTotal / 1e+30).ToString("F") + " Quintillones";
        }
        else if (DineroTotal > 1e+27)
        {
            textDinero = (DineroTotal / 1e+27).ToString("F") + " mil Cuatrillones";
        }
        else if (DineroTotal > 1e+24)
        {
            textDinero = (DineroTotal / 1e+24).ToString("F") + " Cuatrillones";
        }
        else if (DineroTotal > 1e+21)
        {
            textDinero = (DineroTotal / 1e+21).ToString("F") + " Mil Trillones";
        }
        else if (DineroTotal > 1000000000000000000)
        {
            textDinero = (DineroTotal / 1000000000000000000).ToString("F") + " Trillones";
        }
        else if (DineroTotal > 1000000000000000)
        {
            textDinero = (DineroTotal / 1000000000000000).ToString("F") + " mil Billones";
        }
        else if (DineroTotal > 1000000000000)
        {
            textDinero = (DineroTotal / 1000000000000).ToString("F") + " Billones";
        }
        else if (DineroTotal > 1000000000)
        {
            textDinero = (DineroTotal / 1000000000).ToString("F") + " mil Millones";
        }
        else if (DineroTotal > 1000000)
        {
            textDinero = (DineroTotal / 1000000).ToString("F") + " Millones";
        }
        else if (DineroTotal > 1000)
        {
            textDinero = (DineroTotal / 1000).ToString("F") + " mil";
        }

I don’t see anywhere in this code where 1 Billion Billion would be output. 1000 Billion will be output because all your if/else statements have an “off by one” error. You probably want to change all your “>” to “>=”.

1 Like

As @Joe-Censored said, you are likely missing >= instead of >

Imagine you call

else if (DineroTotal > 1000)

to get display mil.
If you put DineroTotal = 1000, you will not see mil.
But if you set DineroTotal = 1001 or greater then it will work.

In fact you will not see anything for DineroTotal = 1000, in your current if else, as you have no condition. Unless you change > to >=

1 Like

Your code doesn’t show the type of DineroTotal, but I’d guess the reason that it isn’t always the same is probably because of floating-point rounding error.

float uses 23 bits for the mantissa, so starting somewhere on the order of 8,000,000 you will no longer be able to represent consecutive integer values (adding +1 or -1 may not do what you expect).

double uses 52 bits for the mantissa, so you may run into that problem around 4,000,000,000,000,000 = 4e15, which is pretty close to the point where you say you’re having trouble.

if I put 1005 then he puts me 1.01k and I do not want that rounding
how can I solve it

the problem comes to me from 1k and if I put 1000 it puts me 100 and if I put 1001 it puts 1k and that keeps happening if I put> = but the billon error goes from 1k upwards

solved i only change ToString(“F”) to ToString(“0.00”)
using >= and doubles