How to display values only upto 2 decimal places

后端 未结 8 2291
南旧
南旧 2020-12-17 19:04

I have a table column \"Amount\" of type money. When I am retrieving its value through a store procedure, it returns the value upto 4 decimal places(because of type money).

相关标签:
8条回答
  • 2020-12-17 19:28
    string.Format("{0:0.00}", your_value);
    
    0 讨论(0)
  • 2020-12-17 19:33

    Read Custom Numeric Formats for detailed instructions on formatting numbers.

    value.ToString("0.00");
    

    In C# 6 or later, you can use string interpolation for a somewhat cleaner syntax.

    $"{value:0.00}";
    
    0 讨论(0)
  • 2020-12-17 19:38
    Text='<%#Bind("Value","{0:F2}") %>'
    
    0 讨论(0)
  • 2020-12-17 19:41

    You can use Standard Numeric Format Example:

    decimal dValue = 1.268;
    string sValue = dValue.ToString("N"); // 1.27
    
    0 讨论(0)
  • 2020-12-17 19:46

    Well, I tried it and got the correct result.

    Below is the code that I used:

    funding.amount= Math.Round(decimal.Parse(dr["Amount"].ToString()), 2).ToString();
    

    //since the amount was of string type, therefore I used the above code. we can also use the below code:

    decimal.Round(yourValue, 2, MidpointRounding.AwayFromZero);
    

    http://msdn.microsoft.com/en-us/library/9s0xa85y.aspx

    0 讨论(0)
  • 2020-12-17 19:48

    In Leave Event write this code

     Double x;
            Double.TryParse(txtLocl.Text, out x);
            txtLocl.Text = x.ToString("0.00");
    

    After leaving it allowed only two decimal places

    0 讨论(0)
提交回复
热议问题