Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display values only upto 2 decimal places

Tags:

c#

sql-server

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). I want the value upto two decimal places and I want it to handle in the code. How will I do it by rounding off the value to 2 decimal place. Thanks

like image 260
Running Rabbit Avatar asked Mar 08 '13 06:03

Running Rabbit


People also ask

How do you limit decimal places to 2?

Rounding a decimal number to two decimal places is the same as rounding it to the hundredths place, which is the second place to the right of the decimal point. For example, 2.83620364 can be round to two decimal places as 2.84, and 0.7035 can be round to two decimal places as 0.70.


1 Answers

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}";
like image 102
p.s.w.g Avatar answered Oct 19 '22 03:10

p.s.w.g