Browse Source

Merge pull request #269 from Krellan/rounding

Fixes column alignment in decimal fields.
Luke-Jr 12 years ago
parent
commit
724ef329f6
1 changed files with 5 additions and 2 deletions
  1. 5 2
      miner.c

+ 5 - 2
miner.c

@@ -2517,7 +2517,9 @@ void pick_unit(float hashrate, unsigned char *unit)
 	unsigned char i;
 	unsigned char i;
 	for (i = 0; i < *unit; ++i)
 	for (i = 0; i < *unit; ++i)
 		hashrate /= 1e3;
 		hashrate /= 1e3;
-	while (hashrate >= 1000)
+	
+	// 1000 but with tolerance for floating-point rounding, avoid showing "1000.0"
+	while (hashrate >= 999.95)
 	{
 	{
 		hashrate /= 1e3;
 		hashrate /= 1e3;
 		if (likely(_unitchar[*unit] != '?'))
 		if (likely(_unitchar[*unit] != '?'))
@@ -2553,7 +2555,8 @@ int format_unit2(char *buf, size_t sz, bool floatprec, const char *measurement,
 	
 	
 	if (floatprec)
 	if (floatprec)
 	{
 	{
-		if (hashrate >= 100 || unit < 2)
+		// 100 but with tolerance for floating-point rounding, max "99.99" then "100.0"
+		if (hashrate >= 99.995 || unit < 2)
 			prec = 1;
 			prec = 1;
 		else
 		else
 			prec = 2;
 			prec = 2;