Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Base.format_bytes(; binary=false) option #50572

Merged
merged 1 commit into from
Jul 23, 2023

Conversation

carstenbauer
Copy link
Member

Add a binary keyword argument to Base.format_bytes that enables switching between the default units KiB, MiB, GiB, etc. and kB, MB, GB. I've wanted this feature multiple times before so I thought I should just make a PR.

julia> Base.format_bytes(12345678)
"11.774 MiB"

julia> Base.format_bytes(12345678; binary=false) # with this PR
"12.346 MB"

@stevengj
Copy link
Member

LGTM.

@stevengj stevengj added display and printing Aesthetics and correctness of printed representations of objects. feature Indicates new feature / enhancement requests labels Jul 19, 2023
@staticfloat staticfloat merged commit 3c5b3c0 into JuliaLang:master Jul 23, 2023
3 checks passed
fredrikekre pushed a commit that referenced this pull request Jan 22, 2024
Introduced in [50572](#50572)

Before:
```
julia> Base.format_bytes(1, binary=false)
"1 "

julia> Base.format_bytes(11, binary=false)
"11 s"
```

This PR:
```
julia> Base.format_bytes(1, binary=false)
"1 byte"

julia> Base.format_bytes(11, binary=false)
"11 bytes"
```
Also add tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. feature Indicates new feature / enhancement requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants