Skip to content

LN_KIB / LN_KB are backwards #26

@mstange

Description

@mstange

https://github.com/hyunsik/bytesize/blob/02822917468b14b6daa5bd76c0522a4f06a1188e/src/lib.rs#L63-L64

The two base values are backwards. This leads to the selection of the wrong unit; values larger than 1000 or lower than 1.0 can be displayed, e.g. "1090.0 GB" or "0.9 TiB".

use bytesize::ByteSize;

fn main() {
    println!("{}", ByteSize::gib(940).to_string_as(true));
    println!("{}", ByteSize::gb(940).to_string_as(false));
    println!("{}", ByteSize::gib(1090).to_string_as(true));
    println!("{}", ByteSize::gb(1090).to_string_as(false));
}

// Output:             Expected output:
// 0.9 TiB             940.0 GiB
// 940.0 GB            940.0 GB
// 1.1 TiB             1.1 TiB
// 1090.0 GB           1.1 TB

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions