• R/O
  • SSH
  • HTTPS

tabtextfinder: Commit


Commit MetaInfo

Revision166 (tree)
Time2019-10-10 14:12:53
Authorneparze

Log Message

improved byte count display format

Change Summary

Incremental Difference

--- TabTextFinderForm.cs (revision 165)
+++ TabTextFinderForm.cs (revision 166)
@@ -468,8 +468,8 @@
468468 labelLines.Text = String.Format( "{0}: {1:N0}/{2:N0}", Resources.Label_Lines, query.FoundLines.Count, status.TotalLines );
469469
470470 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 );
473473 labelElapsed.Text = StringUtil.GetTimeSpanString( status.Elapsed );
474474 }
475475 }
--- Util/StringUtil.cs (revision 165)
+++ Util/StringUtil.cs (revision 166)
@@ -18,28 +18,30 @@
1818
1919 public static string GetTimeSpanString( TimeSpan span )
2020 {
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 );
3227 }
3328
3429 private static readonly string[] prefix = new string[] { "", "K", "M", "G", "T", "P" };
3530 public static string GetPrefixedString( long value )
3631 {
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 );
4143 }
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] );
4345 }
4446 }
4547 }
Show on old repository browser