-
Notifications
You must be signed in to change notification settings - Fork 404
Any way to use fractional length? #1214
-
Often times I need to convert decimals to fractional representation to display to/get input from a user... just for length...
eg.
2.25 in = 2 1/4"
14.625 in = 1' 2 5/8"
Is there any way to do this already that I just haven't come across??
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 4 comments 3 replies
-
You might be able to use this:
var fi = Length.FromFeet(1.1234).FeetInches; fi.ToArchitecturalString(1); // 1' - 1" fi.ToArchitecturalString(2); // 1' - 1 1/2" fi.ToArchitecturalString(5); // 1' - 1 2/5"
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks, I'll take a closer look soon
Beta Was this translation helpful? Give feedback.
All reactions
-
I think this looks useful, can you create a pull request and write some unit tests that cover the new inputs?
- We need to support all registered unit abbreviations for a given culture, such as
ft
and'
. See how it's done inTryParseFeetInches
. - An alternative approach could be to replace fractionals with leading whitespace, such as
1/4
=>.25
so that1' 1/4"
becomes1' .25"
and1' 2 1/4"
becomes1' 2.25"
. Maybe there are pitfalls to that approach, but it might allow us to reuse the existing regex.
Beta Was this translation helpful? Give feedback.
All reactions
-
I would also suggest to improve the existing TryParseFeetInches()
method instead of creating a new method, since it seems useful to those parsing feet and inches.
Beta Was this translation helpful? Give feedback.