improved byte count display format
@@ -468,8 +468,8 @@ | ||
468 | 468 | labelLines.Text = String.Format( "{0}: {1:N0}/{2:N0}", Resources.Label_Lines, query.FoundLines.Count, status.TotalLines ); |
469 | 469 | |
470 | 470 | string counts = StringUtil.GetPrefixedString( status.TotalCounts ); |
471 | - labelBytes.Text = String.Format( "{0}: {1:N0}B", Resources.Label_Bytes, counts ); | |
472 | - labelChars.Text = String.Format( "{0}: {1:N0}ch", Resources.Label_Chars, counts ); | |
471 | + labelBytes.Text = String.Format( "{0}: {1}B", Resources.Label_Bytes, counts ); | |
472 | + labelChars.Text = String.Format( "{0}: {1}ch", Resources.Label_Chars, counts ); | |
473 | 473 | labelElapsed.Text = StringUtil.GetTimeSpanString( status.Elapsed ); |
474 | 474 | } |
475 | 475 | } |
@@ -18,28 +18,30 @@ | ||
18 | 18 | |
19 | 19 | public static string GetTimeSpanString( TimeSpan span ) |
20 | 20 | { |
21 | - long v = span.Ticks / 10000; | |
22 | - if (v < 1000) { | |
23 | - return String.Format( "{0} ms", v ); | |
24 | - } | |
25 | - if (v < 10 * 1000) { | |
26 | - return String.Format( "{0:F2} s", v / 1000.0 ); | |
27 | - } | |
28 | - if (v < 100 * 1000) { | |
29 | - return String.Format( "{0:F1} s", v / 1000.0 ); | |
30 | - } | |
31 | - return String.Format( "{0} s", v / 1000 ); | |
21 | + double msec = Math.Round( span.Ticks / 10000.0 ); | |
22 | + if (msec < 1000) return String.Format( "{0:F0} ms", msec ); | |
23 | + double sec = msec / 1000.0; | |
24 | + if (sec < 10) return String.Format( "{0:F2} s", sec ); | |
25 | + if (sec < 100) return String.Format( "{0:F1} s", sec ); | |
26 | + return String.Format( "{0:F0} s", sec ); | |
32 | 27 | } |
33 | 28 | |
34 | 29 | private static readonly string[] prefix = new string[] { "", "K", "M", "G", "T", "P" }; |
35 | 30 | public static string GetPrefixedString( long value ) |
36 | 31 | { |
37 | - int i = 1; | |
38 | - for (; i < prefix.Length; ++i) { | |
39 | - if (value < 1000) { break; } | |
40 | - value /= 1000; | |
32 | + int unit = 0; | |
33 | + int floats = 0; | |
34 | + double val = 0; | |
35 | + if (value > 0) { | |
36 | + val = value; | |
37 | + int digits = (int) Math.Floor( Math.Log10( val ) ); | |
38 | + double round = Math.Pow( 10, Math.Max( digits - 2, 0 ) ); | |
39 | + val = Math.Round( val / round ) * round; | |
40 | + unit = Math.Min( digits / 3, prefix.Length - 1 ); | |
41 | + val /= Math.Pow( 1000, unit ); | |
42 | + floats = Math.Max( 2 + unit * 3 - digits, 0 ); | |
41 | 43 | } |
42 | - return String.Format( "{0} {1}", value, prefix[i - 1] ); | |
44 | + return String.Format( "{0} {1}", val.ToString( String.Format( "F{0}", floats ) ), prefix[unit] ); | |
43 | 45 | } |
44 | 46 | } |
45 | 47 | } |