public static string ToString(this Decimal myValue, int strLength, byte decimalPos, string justify = "R", bool zeroFill = true, bool showDecimal = true) { char padChar = zeroFill ? '0' : ' '; string s = myValue.ToString("." + new string('0', decimalPos)); //This rounds... if (!showDecimal) { s = s.Replace(".", ""); } string padding = new string(padChar, strLength - s.Length); return (justify == "R") ? padding + s : s + padding; }Then, as examples:
string s = 1234.56M.ToString(10, 2, "R"); s = 1234.56M.ToString(10, 4, "",false); s = 1234.56M.ToString(10, 2, "R",true,false); s = 134.5645676M.ToString(10, 4, ""); s = .5645676M.ToString(10, 4, ""); s = 1.99999M.ToString(10, 4,"",false);The order of the default parameters might be improved tho....