Another little extension method. This one allows easy rounding to a specific number of decimals:
double d = 0.66782423;string s = d.ToString(3); // s = “0.668”
This is done by the following method:
public static class DoubleExtension
{
public static string ToString( this double value, int decimals )
StringBuilder format = new StringBuilder( "0" );
if ( decimals > 0 )
format.Append( "." );
}
for ( int i = 0; i < decimals; i++ )
format.Append( "0" );
return value.ToString( format.ToString() );
dasBlog theme by Mads Kristensen
Concepts LINQ Entity Framework WCF WPF RESTful Web Unit Testing .NET Workflow More >>
Tools Visual Studio Windows IIS Silverlight More >>
Type Screencast Tools Video Newsletter Sample Article Books Magazine How To Demo Course Products More >>