View Single Post
Old 04-12-2006, 02:54 PM  
neoxed
Too much time...
 
Join Date: May 2003
Posts: 1,326
Default

By converting the speed value from bytes to bits (multiply by 8).

Code:
proc ::nxLib::FormatSpeed {speed {seconds 0}} {
    set speed [expr {double($speed) * 8}]
    if {$seconds > 0} {set speed [expr {double($speed) / $seconds}]}
    foreach decimals {0 2 2} unit {Kb/s Mb/s Gb/s} {
        if {abs($speed) < 1024} {break}
        set speed [expr {double($speed) / 1024.0}]
    }
    return [format "%.*f%s" $decimals $speed $unit]
}
neoxed is offline   Reply With Quote