bytesize icon indicating copy to clipboard operation
bytesize copied to clipboard

LN_KIB / LN_KB are backwards

Open mstange opened this issue 4 years ago • 0 comments

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

mstange avatar Jun 12 '21 17:06 mstange