Skip to content

FeetInches.ToString as architectural format #1075

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

Closed
lwestfall opened this issue Apr 20, 2022 · 2 comments · Fixed by #1106
Closed

FeetInches.ToString as architectural format #1075

lwestfall opened this issue Apr 20, 2022 · 2 comments · Fixed by #1106

Comments

@lwestfall
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Not really

Describe the solution you'd like
It would be nice if FeetInches had a method to output a string in architectural format (including fractional inches). Using the example from below, it would output a string like 5' - 4 1/2".

// Note that it isn't customary to use fractions - one wouldn't say "I am 5 feet and 4.5 inches".

Describe alternatives you've considered
An extension method works fine, and I'm happy to do this if it's not desired in this codebase but figured there may be others wishing for similar functionality.

Additional context
This is a pretty common notation in the US in certain contexts. I'm not sure if (the few) other cultures that use feet and inches have a different architectural format, so not sure how CultureInfo might play a role if any.

Related issue (never implemented AFIAK) #676. This would have to be implemented at the same time, so another thing to consider is how to deal with the fractional precision for rounding. Maybe via an argument, like an integer for the denominator?

I can contribute if this is wanted. I'm assuming we wouldn't want to override ToString() or any of it's overloads since that's already established. Maybe it'd be like ToArchitecturalString(int fractionDenom) ?

@angularsen
Copy link
Owner

Hi, adding an ToArchitecturalString() seems reasonable to me.

As for rounding to a denominator, I assume you want to round 0.5 to the lowest form 1/2 instead of 2/4 if 4 was given as the denominator.

These seem relevant:
https://stackoverflow.com/questions/502021/how-do-i-round-a-decimal-to-a-specific-fraction-in-c
https://www.geeksforgeeks.org/reduce-the-fraction-to-its-lowest-form/

We'll figure it out, so please go ahead with a pull request and please provide a few unit test cases too. 😊

@lwestfall
Copy link
Contributor Author

Agreed, I think the fraction should be reduced (after rounding to nearest fraction with precision to the given denominator).

I've already written this as an extension method so should be easy to bring it into this project, I'll include unit tests!

angularsen pushed a commit that referenced this issue Jul 22, 2022
Fixes #1075

* Add FeetInches.ToArchitecturalString and tests
* Fix broken link in readme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants