Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
93a10821
Commit
93a10821
authored
Nov 20, 2023
by
Jeffrey Morgan
Browse files
only show decimal points for smaller file size numbers
parent
be61a817
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
9 deletions
+28
-9
format/bytes.go
format/bytes.go
+28
-9
No files found.
format/bytes.go
View file @
93a10821
package
format
package
format
import
"fmt"
import
(
"fmt"
"math"
)
const
(
const
(
Byte
=
1
Byte
=
1
...
@@ -11,16 +14,32 @@ const (
...
@@ -11,16 +14,32 @@ const (
)
)
func
HumanBytes
(
b
int64
)
string
{
func
HumanBytes
(
b
int64
)
string
{
var
value
float64
var
unit
string
switch
{
switch
{
case
b
>
TeraByte
:
case
b
>=
TeraByte
:
return
fmt
.
Sprintf
(
"%.1f TB"
,
float64
(
b
)
/
TeraByte
)
value
=
float64
(
b
)
/
TeraByte
case
b
>
GigaByte
:
unit
=
"TB"
return
fmt
.
Sprintf
(
"%.1f GB"
,
float64
(
b
)
/
GigaByte
)
case
b
>=
GigaByte
:
case
b
>
MegaByte
:
value
=
float64
(
b
)
/
GigaByte
return
fmt
.
Sprintf
(
"%.1f MB"
,
float64
(
b
)
/
MegaByte
)
unit
=
"GB"
case
b
>
KiloByte
:
case
b
>=
MegaByte
:
return
fmt
.
Sprintf
(
"%.1f KB"
,
float64
(
b
)
/
KiloByte
)
value
=
float64
(
b
)
/
MegaByte
unit
=
"MB"
case
b
>=
KiloByte
:
value
=
float64
(
b
)
/
KiloByte
unit
=
"KB"
default
:
default
:
return
fmt
.
Sprintf
(
"%d B"
,
b
)
return
fmt
.
Sprintf
(
"%d B"
,
b
)
}
}
switch
{
case
value
>=
100
:
return
fmt
.
Sprintf
(
"%d %s"
,
int
(
value
),
unit
)
case
value
!=
math
.
Trunc
(
value
)
:
return
fmt
.
Sprintf
(
"%.1f %s"
,
value
,
unit
)
default
:
return
fmt
.
Sprintf
(
"%d %s"
,
int
(
value
),
unit
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment