Humanizer (humanized)
Humanizer meets all your. NET needs for manipulating and displaying strings, enums, dates, times, Timespans, numbers and q Uantities
String
Return a string describing the value as a file size.//for example, 1.23 mb.public static string tofilesize (this double Value) { string[] suffixes = {"bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}; for (int i = 0; i < suffixes. Length; i++) { if (value <= (Math.pow (1024x768, i + 1)) { return threenonzerodigits (Value/ Math.pow (1024, i) + "" + suffixes[i]; } } return Threenonzerodigits (Value/ Math.pow (1024x768, suffixes. LENGTH-1) + "" + suffixes[suffixes. LENGTH-1];}
Return the value formatted to include at most three//non-zero digits and at most of the digits after the//decimal point. examples:// 1// 123// 12.3// 1.23// 0.12private static string threenonzerodigits (double value) { if (value >=) { //No digits after the decimal. return value. ToString ("0,0"); } else if (value >=) { //one digit after the decimal. return value. ToString ("0.0"); } else { //digits after the decimal. return value. ToString ("0.00");} }
C # extension Method set