How to replace empty spaces in a doubles array? - C #

0

I hope you can help me with a problem I have in c #. I'm creating a program for pseudorandom numbers, and all these numbers are stored inside a doubles array. The problem that I present, is that once I execute the program, it tries to look inside the array for all the numbers after the decimal point to make a comparison. For example (0.1111,0.2222,0.333 ..), the question is that it stops working once it reaches a whole number, because although I have it rounded it can not find anything after the decimal point, and that's when it fails. So I want to know, if there is a way to assign a "0" within those empty spaces. For example (1,000,2,000,3,000). I hope you have explained me. Thank you very much, I leave my code

              double x0, c, a, mod, tablaquintilla =0.0, tablapoker =0.0, 
              tablatercia = 0.0, tabladospares = 0.0, tablapar = 0.0, 
              tablapachuca = 0.0;
              double tablafull = 0;
                int n;
                char c1, c2, c3, c4, c5;
                double quin = 0.0, poke = 0.0, full = 0.0, ter = 0.0, dpar = 0.0, par = 0.0, pach = 0.0, chical;
                string compar;

                //VALORES DE LAS TABLAS PARA SHI EN POKER
                double pokertabla99 = 16.81;

                //RECOGEMOS LOS DATOS DE LAS CAJAS DE TEXTO

                x0 = Convert.ToDouble(txtSemilla2.Text);
                c = Convert.ToDouble(txtC2.Text);
                a = Convert.ToDouble(txtAlpha2.Text);
                mod = Convert.ToDouble(txtM2.Text);
                n = Convert.ToInt32(txtN2.Text);
                //DECLARAMOS NUESTRO ARRAY DE N NUMEROS PORQUE ESTOS SE ASIGNARAN CUANDO EL USUARIO TECLEE LA CANTIDAD
                double[] array = new double[n];
                //OBTENEMOS LA LISTA
                List<double> milista = new List<double>();

                //INICIAMOS EL CICLO PARA NUMEROS 
                for (int i = 0; i < n; i++)
                {

                    //OBTENEMOS LOS NUMEROS PSEUDOALEATORIOS 
                    double result = (((x0 * a) + c) % mod);
                    x0 = result;
                    double resultado = Math.Round((result) / (mod - 1),6);
                    milista.Add(resultado);//PARA FINES MAS PRACTICOS QUE SE UTILIZARAN EN LAS DEMAS PRUEBAS GUARDAMOS EN UNA LISTA LOS RESULTADOS
                                           //UTILIZANOS UN ARRAY
                    array[i] = resultado;


                }
                for (int i = 0; i < array.Length; i++)
                {


                    c1 = Convert.ToChar(array[i].ToString().ElementAt(2));
                    c2 = Convert.ToChar(array[i].ToString().ElementAt(3));
                    c3 = Convert.ToChar(array[i].ToString().ElementAt(4));
                    c4 = Convert.ToChar(array[i].ToString().ElementAt(5));
                    c5 = Convert.ToChar(array[i].ToString().ElementAt(6));'
                    if (c1 == c2 && c1 == c3 && c1 == c4 && c1 == c5)
                    {
                        quin = quin + 1.0;
                        tablaquintilla = 0.0001 * n;
                    }
    
asked by elias459 04.11.2018 в 20:25
source

1 answer

0

You could format the string using

string nroString = array[i].ToString("N3");

c1 = Convert.ToChar(nroString.ElementAt(2));
c2 = Convert.ToChar(nroString.ElementAt(3));
//resto codigo

When you indicate the "N3" format, you indicate that it will be a number with 3 decimals.

Strings with standard numeric format

But validate the culture you are using, because if it is ES-es use the comma as a decimal separator, you have to use for example En-us to use the point as a decimal separator

    
answered by 05.11.2018 / 01:18
source