Skip to content

Parsing negative FeetInches values #673

Closed
@deanwiles

Description

@deanwiles

Describe the bug
Unexpected behavior from Length.ParseFeetInches when parsing negative coordinates.

We have an application that imports values on the x- and y-axes relative to a home position. A position that is 11 ft 2 in from the left of center has an x value of -11'2". Note that the negative sign applies to both feet and inches, essentially meaning -(11'2"). Unfortunately Length.ParseFeetInches evaluates -11'2" as -10'-10" (effectively -11' plus 2").

It appears that Length.ParseFeetInches is expecting two negative signs when parsing negative values (e.g. -11'-2"). Is that the correct behavior? I've never seen multiple negatives in coordinates, but I also couldn't find any defined standard for this online.

To Reproduce
Samples from Visual Studio Debugger Immediate Window:
?Length.ParseFeetInches("-11'2"").FeetInches.ToString()
"-10 ft -10 in"
?Length.ParseFeetInches("-11 ft 2 in").FeetInches.ToString()
"-10 ft -10 in"
?Length.ParseFeetInches("-11'-2"").FeetInches.ToString()
"-11 ft -2 in"
?Length.ParseFeetInches("-11 ft -2 in").FeetInches.ToString()
"-11 ft -2 in"
?Length.ParseFeetInches("-(11'2")").FeetInches.ToString()
throws 'System.FormatException'

Expected behavior
I expected that the leading negative sign would apply to the entire unit (e.g. -11'2" = -(11'2")).

Comments
I really like UnitsNet! Very robust and flexible. (Just wasn't expecting this behavior.)

It doesn't appear that Length.ParseFeetInches handles parentheses, so if the current behavior is correct, I may have to detect and strip off leading negatives and then multiply by -1 after parsing.

Thanks, Dean.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions