nagyistoce / tin-man

Automatically exported from code.google.com/p/tin-man
GNU General Public License v3.0
0 stars 0 forks source link

Culture-related parsing problems #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Error in file Parser.cs

private double AsDouble(string s) {
        double d;
        if (!double.TryParse(s, out d))
            SemErr("Unable to convert \"" + s + "\" to a double.");
        return d;
    }
Get an error if for example s = "123.45"
separator "." or "," depending on regional settings
You can fix so
private double AsDouble(string s) {
        double d;
        s = s.Replace(".", ",");
        if (!double.TryParse(s, out d))
            SemErr("Unable to convert \"" + s + "\" to a double.");
        return d;
    }

Thank you for tin-man :)

Original issue reported on code.google.com by bort6...@gmail.com on 12 Feb 2011 at 6:10

GoogleCodeExporter commented 9 years ago
Thank you for your bug report.  Unfortunately if I were to use the fix you 
propose, then it would stop working in cultures that use '.' as a separator.

The rcssserver3d does not consider regional formatting and that therefore it 
always uses '.' for decimal points in the messages it sends out.  Therefore, 
TinMan should always use that separator too.

As I understand it, the correct thing to do here is to specify an invariant 
culture for the parse, such as this:

    if (!double.TryParse(s, out d, CultureInfo.InvariantCulture))

I will update the code now to specify this at any parse points I find through 
the code.

Thank you very much for your feedback and for your interest in TinMan :)

Original comment by drewnoakes on 12 Feb 2011 at 12:29

GoogleCodeExporter commented 9 years ago

Original comment by drewnoakes on 12 Feb 2011 at 12:29

GoogleCodeExporter commented 9 years ago
FYI the code I used above was incorrect.  It should be:

    if (!double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out d))

Original comment by drewnoakes on 12 Feb 2011 at 12:32

GoogleCodeExporter commented 9 years ago
This bug has been fixed as of version 0.4.3.  This will be important for teams 
who wish to run their agents in competitions hosted in other countries.

Could you please verify that this fix works for you?

Original comment by drewnoakes on 12 Feb 2011 at 1:33

GoogleCodeExporter commented 9 years ago
Yes. This correction rectifies an error.
Everything works fine, thanks.

Original comment by bort6...@gmail.com on 14 Feb 2011 at 6:35

GoogleCodeExporter commented 9 years ago
Thanks for letting me know. If you have any questions or suggestions for 
TinMan, please don't hesitate to let me know, either via this issue tracker or 
email.

Original comment by drewnoakes on 14 Feb 2011 at 10:45

GoogleCodeExporter commented 9 years ago

Original comment by drewnoakes on 6 Apr 2011 at 2:56