tags:

views:

54

answers:

2

i have value of 1.564 and 1.565 i need round this value to 1.56 and 1.56,which function suitable for this in c#.

+5  A: 

do a multiply by 100 followed by a floor and followed by a divide by hundred. I am sure that there is a better way of doing it though

Math.floor(n*100)/100
codebreach
On C# that's `Floor`, by the way.
Kobi
+2  A: 

To remove the less significant digits (1.348 -> 1.34):

Math.Floor(number * 100) / 100;

To round the number to two decimals:

Math.Round(number, 2);

To represent it as a string, for display:

number.ToString("#.00");
Kobi
for this 1.5674 and 1.5675 how can i
ratty
How can you what?
Kobi
ratty
the same with `1000`, `3` and `#.000`. This assumes you need a **fixed number of decimals**. Do you need a function that removes the last digit? That is weird, isn't it?
Kobi