Sunday, November 21, 2010

Return 2 decimal places without rounding

This function returns 2 decimal places without rounding. This function requires to pass decimal value parameter.


private string FormatDecimal(decimal val)
{
decimal newValue = ((Int64)(val * 100)) / 100m;
return newValue.ToString("N2");
}


for example:

decimal dValue = 22221111.8055234M;
string newValue = FormatDecimal(dValue);


Output:
newValue = 22,221,111.80

No comments: