Diff

Differences From Artifact [7620b741b7]:

To Artifact [bd38f11c13]:


1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302


1303
1304
1305

1306
1307
1308

1309
1310
1311

1312
1313

1314
1315

1316
1317
1318
1281
1282
1283
1284
1285
1286
1287

1288


1289

1290

1291
1292





1293
1294



1295



1296



1297


1298
1299

1300
1301
1302
1303







-

-
-

-

-


-
-
-
-
-
+
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
+

-
+



}

proc ::nano::balance::toHuman {raw {decimals 3}} {
	set humanUnit [normalizeUnitName _USER]
	set humanUnitMultiplier [dict get $::nano::balance::_conversion $humanUnit]

	if {$raw > [expr {$humanUnitMultiplier / 10000000}]} {
		set balance [toUnit $raw $humanUnit 7]
		set baseUnit $humanUnit
		set balance [expr {entier($balance * 1000000)}]
		set labels {u m "" K M G T}
	} else {
		set balance $raw
		set baseUnit "raw"
		set labels {"" K M G T}
	}

	set labelIdx -1
	foreach label $labels {
		incr $labelIdx

		if {$balance < 1000} {
	set balance [toUnit $raw $baseUnit $decimals]
	set work [split $balance "."]
			break
		}

	set leading  [lindex $work 0]
		set balance [expr {$balance / 1000}]
	}

	set trailing [string trimright [lindex $work 1] "0"]
	set unit "${label}${baseUnit}"
	set unit [normalizeUnitName $unit]

	set balance [join [list $leading $trailing] "."]
	set balance [toUnit $raw $unit $decimals]
	set balance [string trimright $balance "0."]
	set balance [string trimright $balance "."]

	set result [list $balance $unit]
	set result [list $balance $baseUnit]

	return $result
}