/// <summary> /// Converts to formatted string /// </summary> /// <param name="width">Character width of oen matrix element</param> /// <param name="numDecimals">Number of decimal places</param> /// <returns>Matrix data content in a string</returns> public string toFormatString(int width, int numDecimals) { DoubleFormatter dblF = new DoubleFormatter(width, numDecimals); StringBuilder sb = new StringBuilder(); sb.AppendLine(); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { string s = string.Format(dblF, "{0}", A[i, j]); int padding = Math.Max(1, width - s.Length); //at least 1 space for (int k = 0; k < padding; k++) { sb.Append(' '); } sb.Append(s); } sb.AppendLine(); } sb.AppendLine(); return(sb.ToString()); }
public string toFormatString(int width, int numDecimals) { DoubleFormatter dblF = new DoubleFormatter(width, numDecimals); StringBuilder sb = new StringBuilder(); sb.AppendLine(); for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { string s = string.Format(dblF, "{0}", A[i][j]); int padding = Math.Max(1, width-s.Length); //at least 1 space for(int k = 0; k < padding; k++) { sb.Append(' '); } sb.Append(s); } sb.AppendLine(); } sb.AppendLine(); return sb.ToString(); }