So i want 12.6666667 to show up as 12.6 and not 13 or 12.67 This is what i have done
Math.Round((5 * (53 - 32)) / 9, 1)
So i want 12.6666667 to show up as 12.6 and not 13 or 12.67 This is what i have done
Math.Round((5 * (53 - 32)) / 9, 1)
Math.Truncate (x * 10.0) / 10.0
is one way to do it.
Using your numbers:
double x = 5.0 * (53.0 - 32.0) / 9.0;
double result = Math.Truncate (x * 10.0) / 10.0;
Note the use of ".0" at the end of all numbers, this ensures that floating-point math, and not integer math, is used when combining them. Integer math will remove any remainders when dividing numbers, while floating point will keep the stuff to the right of the decimal point, which is what you want.
If you want formatting (as John has suggested in the comment):
String.Format("{0:0.0}", 12.6666666); // Note: this shows up as 12.7
d -= d % 0.1; //Where 0.1 is the desired least significant unit.
It should truncate rather than round at whatever precision you would like, and it seems to work fine on negative numbers as well, always rounding towards zero.
If you want 12.6666667 to show up as 12.6, you'll have to truncate, not round; otherwise you'd get 12.7 to one decimal place.
Personally I'd do that by going ((int) (12.6666667 * 10)) / 10.