fsprojects / FSharp.Configuration

The FSharp.Configuration project contains type providers for the configuration of .NET projects.
http://fsprojects.github.io/FSharp.Configuration/
Other
114 stars 63 forks source link

Problem with floating point scalars #57

Closed Turee closed 9 years ago

Turee commented 9 years ago

When i try to define floating point numbers in yaml files type provider reports following error: 'FSharp.Configuration.ConfigTypeProvider+FSharpConfigurationProvider' reported an error: Input string was not in a correct format.

Example yaml file (issue reproduces):

Test:
    AFloatingPointNumber: 0.1

This works fine:

Test:
    AIntegerNumber: 1
vasily-kirichenko commented 9 years ago

Try 0,1.

Turee commented 9 years ago

That seems to work. I browsed the type provider code and i thought the parsing is culture invariant. Shouldn't this be the case?

Edit: Atleast TypeProviders.Helpers.fs has CultureInfo.InvariantCulture passed to Double.TryParse. (line 123):

    let (|Float|_|) = tryParseWith (fun x -> Double.TryParse(x, NumberStyles.Any, CultureInfo.InvariantCulture))
vasily-kirichenko commented 9 years ago

What do you suggest to fix it? It should be able to parse floats with any decimal separator on machines with any culture.

Turee commented 9 years ago

I do not have a fix yet but i can look into it. Just wanted to make sure this is not a known issue.

Turee commented 9 years ago

The issue was with the SharpYaml failing to parse the 0.1 formatted double value. => Updated SharpYaml that now works. Second issue was with calling a double values ToString() method, which is not culture invariant. Then parser parsed the double with culture invariant setting on resulting invalid results.

Turee commented 9 years ago

I'm creating a pull request.