0

I have a table with different numbers and I would like to put spaces every 3 numbers.

For example : 1500 = 1 500 or 10000 = 10 000

My table

My code :

<div class="table-responsive" style="padding-top:30px;">
<table class="table table-bordered">
    <thead>
        <tr>
            @foreach (string row in ViewBag.ListEntete)
            {
                <th>@row</th>
            }
        </tr>
    </thead>

    <tbody>
        @{
            List<List<string>> listHisto = ViewBag.ListHisto;

            bool isClassSuccess = true;
            string classLigne;

            foreach (List<string> item in listHisto)
            {
                if (isClassSuccess)
                {
                    classLigne = "class=warning";//jaune clair
                    isClassSuccess = false;
                }
                else
                {
                    classLigne = "class=success";//vert clair
                    isClassSuccess = true;
                }
                @:<tr @classLigne>
                    foreach (string row in item)
                    {
                        <td>@row</td>
                    }
                @:</tr>
            }


            @:<tr class="active">
                <td>CUMUL</td>
                foreach (string row in ViewBag.ListCumul)
                {
                    <td>@row</td>
                }
            @:</tr>              
        }
    </tbody>
</table>

My numbers are in a list.

dac = new SqlDataAdapter(sql, cn);
            dsc = new DataSet();
            dac.Fill(dsc, "histo");

            List<List<string>> listHisto = new List<List<string>>();
            foreach (DataRow row in dsc.Tables["histo"].Rows)
            {
                List<string> listRow = new List<string>();

                listRow.Add(row["ENTITE"].ToString());
                listRow.Add(row["M01"].ToString());
                listRow.Add(row["M02"].ToString());
                listRow.Add(row["M03"].ToString());
                listRow.Add(row["M04"].ToString());
                listRow.Add(row["M05"].ToString());
                listRow.Add(row["M06"].ToString());
                listRow.Add(row["M07"].ToString());
                listRow.Add(row["M08"].ToString());
                listRow.Add(row["M09"].ToString());
                listRow.Add(row["M10"].ToString());
                listRow.Add(row["M11"].ToString());
                listRow.Add(row["M12"].ToString());
                listRow.Add(row["TT"].ToString());
                listHisto.Add(listRow);
            }
            list.Add("histo", listHisto);

I tried to change row["M09"].ToString() by row["M09"].ToString("n", nfi) but I have this errors :

errors

Thanks in advance for your help

ElGecko
  • 69
  • 4
  • What is "coin format"? Could you just use a single space as a thousand separator? Also *PLEASE* remove non-relevant code. It makes your question a lot *harder* to understand. You don't avoid close- or down-votes this way, you *attract* them – Panagiotis Kanavos Dec 12 '16 at 09:17
  • Sorry, it's corrected – ElGecko Dec 12 '16 at 09:23
  • What you ask is called the thousand or grouping separator. Check the duplicate question, it answers exactly how to use spaces as a thousand separator – Panagiotis Kanavos Dec 12 '16 at 09:26
  • I tried to do the same but it does not work ... It is not possible to do a toString () on @row ? – ElGecko Dec 12 '16 at 09:46
  • Your `row` is already a string. You need to change the code that converts the number to a string. That's why I said earlier that you should post the *relevant* code. Where is the code that generates the strings? Do you read the values from a database? A REST API? – Panagiotis Kanavos Dec 12 '16 at 09:48
  • I have not put the code because it is an SQL query that fills a list of string, in this query there are numbers. I updated my post. – ElGecko Dec 12 '16 at 09:58
  • And yet, that `ToString` is what converts the numbers to text. That's the relevant code which you need to modify to `ToString("n",nfi);`. Or, *don't* use `ToString` there, return a list of numbers and leave formatting to the view – Panagiotis Kanavos Dec 12 '16 at 10:01
  • Sorry I don't understand .. :( I must convert the string to int ? – ElGecko Dec 12 '16 at 10:04
  • As other are suggesting, you are dealing with strings, obtained we don't know how, and this does not help you. You should get some numeric data(e.g a `List>` instead of `List>`): then it's quite easy to format them the way you prefer. – Gian Paolo Dec 12 '16 at 10:08
  • Just change `row["M09"].ToString()` into `row["M09"].ToString("n",nfi)`, as shown in the duplicate question – Panagiotis Kanavos Dec 12 '16 at 10:10
  • Not work ("No overload for the toString () method accepts arguments 2") :/ You can see the screen in my post and I have the same problem with de List ("Can not convert string to int") – ElGecko Dec 12 '16 at 10:33

0 Answers0