How to display values ​​only up to two decimal places

I have a column in the Sum table of type money. When I return its value through the repository procedure, it returns a value of up to 4 decimal places (due to the type of money). I want a value of up to two decimal places, and I want it to handle the code. How to do this by rounding the value to 2 decimal places. Thanks

+5
source share
5 answers

Ok, I tried and got the correct result.

Below is the code I used:

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

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

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

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

+1
source

.

value.ToString("0.00");
+13

Format in presentation layer:

string.Format("{0:#.##}", value);
+3
source

You can use Standard Digital Format Example:

decimal dValue = 1.268;
string sValue = dValue.ToString("N"); // 1.27
0
source

In the Remaining Event write this code

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

After exiting it, only two decimal places are allowed

0
source

All Articles