I have an overloaded extension method which rounds either a decimal or double to N number of decimal places and it works perfectly.
public static class NumberExtensions
{
public static string ToStringNDecimalPlaces(this double dbValue, int nDecimal)
{
return dbValue.ToString("N" + nDecimal);
}
public static string ToStringNDecimalPlaces(this decimal dbValue, int nDecimal)
{
return dbValue.ToString("N" + nDecimal);
}
}
My question is, I want to create another called something like, "ToStringFirstDecimalPlace" or something like that which takes the decimal value and rounds it to the first logical decimal value after the 0s. Let me give some, this is how I would like the method to work:
e.g.
- 0.000345879 = 0.0003
- 0.019356 = 0.02
- 0.1 = 0.1
So it ignores the leading 0s and takes the nth to be the first logical number that makes sense instead of just rounding to 0.0 for example.