-
Notifications
You must be signed in to change notification settings - Fork 965
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
Number to number extensions #518
Comments
In another hand, you could use var size = "20M".FromMetric(); // 20 millions or var size = "20k".FromMetric(); // 20 thousands It will works as expected. |
And if you really want to use words: private static T UseMetric<T>(this T input, string unit)
{
return (input + unit).FromMetric();
}
public static long Millions(this long input)
{
return input.UseMetric<long>("M");
} If you dont want to use "Metric": private static T MultiplyByTen<T>(this T input, string unit)
{
return input * Math.Pow(10, unit);
}
public static long Millions(this long input)
{
return input.MultiplyByTen(6);
} My only concern for both is performance. |
From the performance point of view the proposed implementation in #519 is pretty good, as it only uses simple multiplication with a constant. Further the proposal provides implementations for the common numeric types, where |
I know. This is why I added "My only concern for both is performance." at the end of my post. "Both" are
I can change that if you think it is worth it. Sorry If my comments were mistaken. I just share some alternatives. I think #519 is a good idea. The implementation is simple, stupid and works very well. 👍 |
I wonder how you would achieve this, as the method can't be overloaded only by changing the result type. You don't have to be sorry, to be able to discuss on alternatives is always good 👍. It drives learning other approaches to the problem and an alternative can be a good fit in some other scenario for anyone reading this discussion someday. |
I think it would be nice to add to the convenient extensions for
TimeSpan
,ByteSize
extensions that simplify writing big numbers, for example:Instead of:
It's clearer to read, simpler to write and reduces the chance for errors.
I plan on using this extensively in my configuration defaults (e.g.
BounedCapacity = 10.Millions()
,MaxDegreeOfParallelism = 1.Thousands()
)The text was updated successfully, but these errors were encountered: