two decimal for label

RAVI 936 Reputation points
2024-05-04T14:42:56.72+00:00

Hello

This is my sample code

Label LRO = e.Item.FindControl("LRO") as Label;

        LRO.Text  = roff; 

         

its should return value in something example two digit decimal

12.45

14.00

15.12

how to do so thanks

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,317 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
306 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 26,166 Reputation points
    2024-05-04T19:06:57.44+00:00

    its should return value in something example two digit decimal

    You have asked this formatting question many times recently. Read the docs...

    https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

    https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

    The following example assumes LRO exists and has a value.

    Label LRO = e.Item.FindControl("LRO") as Label;
    string val = LRO.Text
    decimal val = 0m;
    if(!decimal.TryParse(stringVal, out val))
    {
        //There was an error parsing the string
    }
    Console.WriteLine(val.ToString("#.##"));
    
    0 comments No comments

  2. Lan Huang-MSFT 26,521 Reputation points Microsoft Vendor
    2024-05-06T07:49:03.0633333+00:00

    Hi @RAVI,

    You can use the following code:

    string roff = "12";
    Label LRO = e.Item.FindControl("LRO") as Label;
    decimal val = Convert.ToDecimal(roff);
    LRO.Text = val.ToString("n2");  
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments