File tree Expand file tree Collapse file tree 1 file changed +3
-7
lines changed Expand file tree Collapse file tree 1 file changed +3
-7
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ declare -ga __BYTES_UNITS=(
34
34
)
35
35
36
36
fmt::__deps () {
37
- sys::ensure_has_commands bc
37
+ sys::ensure_has_commands awk
38
38
}
39
39
40
40
fmt::__get_unit_factor () {
@@ -78,7 +78,7 @@ fmt::bytes() {
78
78
local max_unit=${2:- EB}
79
79
80
80
local -i magnitude
81
- magnitude=$( echo " scale=0; l( $bytes ) / l (1024)" | bc -l )
81
+ magnitude=$( awk " BEGIN {print int(log( $bytes ) / log (1024))} " )
82
82
83
83
local unit=' '
84
84
if [[ -n " $max_unit " ]]; then
@@ -102,11 +102,7 @@ fmt::bytes_to() {
102
102
local value
103
103
104
104
conversion_factor=$( fmt::__get_unit_factor " $unit " )
105
- value=$( echo " scale=2; $bytes / $conversion_factor " | bc -zl)
106
- # Add .00 if the value has no dot
107
- if [[ $value != * " ." * ]]; then
108
- value+=' .00'
109
- fi
105
+ value=$( awk " BEGIN {printf \" %.2f\" , $bytes / $conversion_factor }" )
110
106
111
107
echo " $value $unit "
112
108
}
You can’t perform that action at this time.
0 commit comments