Skip to content

Dynamic Unit Selection #831

Closed
Closed
@AndyNetDuma

Description

@AndyNetDuma

Is your feature request related to a problem? Please describe.
I would like to take a unit and write it with the simplest unit available. I.E. 1000mb should become 1gb. Ideally with 1024 bit division support. Very sorry if this is already a feature and I missed it, seems hard to believe nobody needed this before

Describe the solution you'd like
An overload of tostring or perhaps another function that finds the best unit before conversion. For mb it would require a concept of bits and bytes as it some cases I wish to show 1 or the other.
Another option is to take a unit and to provide a function to set the optimal base unit

Describe alternatives you've considered
We currently use a custom conversion system which is messy, I am hoping UnitsNet will do much better however without this vital feature it's, unfortunately, effectively useless to us. So sticking with that is the current alternative.

Additional context
An example:

var a = new UnitsNet.Information(2000, InformationUnit.Megabit);
var b = a.ToString(); // Gives 2000mb
var c = a.ToOptimalUnit(InformationUnit.Bit); // Should give 2gb in bits
var c = a.ToOptimalUnit(InformationUnit.Bytes, 1); // Should give ~2gb in bytes. 1 is optional decimal points

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions