Home > Enterprise >  Covert to custom numeric format strings in ASP.NET MVC / C#
Covert to custom numeric format strings in ASP.NET MVC / C#

Time:08-31

I am trying to custom numeric format strings ASP.NET MVC SQL Server.

Achieved Results: 111345111.2233

Required Results: 111,345,111.223300

Index.aspx Code

<asp:Label ID="Label1" runat="server" Text="label"></asp:Label>

Index.aspx.cs Code

SqlCommand cmd = new SqlCommand("SELECT sum(book_stock) from alpha_tbl;", con);
            
Label1.Text = cmd.ExecuteScalar().ToString();
con.Close();

CodePudding user response:

Use

var x = Convert.ToDecimal(cmd.ExecuteScalar());
Label1.Text = x.ToString("N6");

First convert object to decimal.

https://dotnetfiddle.net/wyqpGV

  • Related