Check-in [dd09cf79e5]
Overview
Comment:Simplified balance to human readable handling to only deal with two units -- Nano and raw
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: dd09cf79e5a64d9dbc1076a5ad4624d790be7a92037b9106a6266d547f5fca78
User & Date: rkeene on 2018-07-11 17:04:07
Other Links: manifest | tags
Context
2018-07-11
17:23
Added a complete block generation cycle test check-in: 33f9a7b27a user: rkeene tags: trunk
17:04
Simplified balance to human readable handling to only deal with two units -- Nano and raw check-in: dd09cf79e5 user: rkeene tags: trunk
16:52
Corrected link to manual check-in: ea4f944294 user: rkeene tags: trunk
Changes

Modified nano.tcl from [7620b741b7] to [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
}