Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToString() with the closest unit? #1290

Open
aradalvand opened this issue Jul 15, 2023 · 3 comments
Open

ToString() with the closest unit? #1290

aradalvand opened this issue Jul 15, 2023 · 3 comments

Comments

@aradalvand
Copy link

aradalvand commented Jul 15, 2023

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 aradalvand changed the title Humanizer? ToString() with the closest unit? Jul 15, 2023
@angularsen
Copy link
Owner

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?

@aradalvand
Copy link
Author

aradalvand commented Jul 16, 2023

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.

@angularsen
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants