ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

DisplayDouble

Converts a Double to a String with precision

Source

public static string DisplayDouble(this double value, int precision)
{
    return value.ToString("N" + precision);
}

Example

double number = 2.2365;

string display = number.DisplayDouble(2); // 2.24

Author: K M Thomas

Submitted on: 25 mrt 2016

Language: C#

Type: System.Double

Views: 3727