UnitsNet icon indicating copy to clipboard operation
UnitsNet copied to clipboard

ToString() with the closest unit?

Open aradalvand opened this issue 1 year ago • 3 comments

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.

aradalvand avatar Jul 15 '23 20:07 aradalvand

Hi, there is no support for this. We could offer some basic support I guess to provide a bit more support out of the box, but it would really duplicate some of the efforts that Humanizer already has done. Why not just use Humanizer?

angularsen avatar Jul 16 '23 16:07 angularsen

Much of Humanizer's functionality when it comes to units overlaps with UnitsNet's, so using both is a bit awkward, I was hoping UnitsNet would have some basic support in this regard.

aradalvand avatar Jul 16 '23 21:07 aradalvand

If you are interested in attempting a pull request to add this functionality, I'm happy to assist. Let me know.

I don't think it will happen otherwise, I have very limited time to spend on this project.

angularsen avatar Jul 16 '23 23:07 angularsen

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jul 08 '24 17:07 github-actions[bot]

.

aradalvand avatar Jul 08 '24 18:07 aradalvand

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 08 '24 02:08 github-actions[bot]

This issue was automatically closed due to inactivity.

github-actions[bot] avatar Aug 16 '24 02:08 github-actions[bot]