Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit a decimal number? [duplicate]

Possible Duplicate:
How to format a decimal

How can I limit my decimal number so I'll get only 3 digits after the point?

e.g  2.774 
like image 213
aharon Avatar asked Jul 09 '10 12:07

aharon


People also ask

How do you restrict decimals?

Now you can limit the decimal places. Select the cell with a number (here, B2) and in the Menu, go to Format > Number > More Formats > Custom number format.

How do I restrict decimal places in Excel?

Select the cells that you want to format. On the Home tab, click Increase Decimal or Decrease Decimal to show more or fewer digits after the decimal point.


2 Answers

Math.Round Method (Decimal, Int32)

Example:

Math.Round(3.44, 1); //Returns 3.4. 
like image 90
Pranay Rana Avatar answered Oct 06 '22 20:10

Pranay Rana


I'm assuming you really mean formatting it for output:

Console.WriteLine("{0:0.###}", value); 
like image 35
Matthew Flaschen Avatar answered Oct 06 '22 21:10

Matthew Flaschen