ChrisMarinos/FSharpKoans

Suggested Double parsing method in ``about the stock example`` koan is locale-dependent

Closed this issue · 2 comments

My locale:

$ echo $LANG
pl_PL.UTF-8

Using System.Double.Parse as suggested in the comments causes an error:

You have not yet reached enlightenment ...
Unknown char: .

Please meditate on the following code:
  at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in <filename unknown>:0 
  at System.Double.Parse (System.String s) [0x00000] in <filename unknown>:0 
  at FSharpKoans.about the stock example+result@64-10.Invoke (System.String[] a) [0x00000] in <filename unknown>:0 
  at FSharpKoans.about the stock example.YouGotTheAnswerCorrect () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 

I suggest adding a locale-agnostic parse function definition to the koan source, for example:

let parseToDouble str = 
  System.Double.Parse (str, System.Globalization.CultureInfo.InvariantCulture)

+1. I also ran into this problem and planned to open an issue when I found this. I also had to add CultureInfo.InvariantCulture to run the code on my Macbook with Norwegian language setup.

Fixed with #36