Skip to content

ToString() with the closest unit? #1290

@aradalvand

Description

@aradalvand

I was expecting UnitsNet to already include this functionality and I'm surprised that it doesn't (if it does and I'm missing something, please let me know).

Consider the following:

var size = Information.FromBytes(10000000);

I want to print size in a human-friendly style. When I do size.ToString(), I get "1e+07 B"; but what I would ideally want is "10 MB", I want it to detect the most reasonable/closest unit it can display the value with, and use that in the string.

Is this not possible? I would think it's a pretty common thing to need to do.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions