Bug in the "float.Parse" method
-
Hi My Friends I develop software with C#.Net 2005, Yesterday installed Borland Delphi 2006 on my PC for debugging and working another program, Delphi work correct and no problem but when switch to C#, see Runtime Error about float.Parse method. For example if you write float f = float.Parse("2.3"); See below Runtime Error : Input string was not in a correct format. This method work in the previous and at now work on the another PC, I think System library conflict with delphi.:confused: If you have solution for me, I will grateful from you. Best Regards, Reza Shojaee
-
Hi My Friends I develop software with C#.Net 2005, Yesterday installed Borland Delphi 2006 on my PC for debugging and working another program, Delphi work correct and no problem but when switch to C#, see Runtime Error about float.Parse method. For example if you write float f = float.Parse("2.3"); See below Runtime Error : Input string was not in a correct format. This method work in the previous and at now work on the another PC, I think System library conflict with delphi.:confused: If you have solution for me, I will grateful from you. Best Regards, Reza Shojaee
Could this be a localization issue? Try specifying the IFormatProvider.
float f = float.Parse("2.3", NumberFormatInfo.InvariantInfo);
Scott P"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
-
Hi My Friends I develop software with C#.Net 2005, Yesterday installed Borland Delphi 2006 on my PC for debugging and working another program, Delphi work correct and no problem but when switch to C#, see Runtime Error about float.Parse method. For example if you write float f = float.Parse("2.3"); See below Runtime Error : Input string was not in a correct format. This method work in the previous and at now work on the another PC, I think System library conflict with delphi.:confused: If you have solution for me, I will grateful from you. Best Regards, Reza Shojaee
-
Could this be a localization issue? Try specifying the IFormatProvider.
float f = float.Parse("2.3", NumberFormatInfo.InvariantInfo);
Scott P"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
Thank you for your guidance, I test your solution and get appropriate result. But do you know why in the previous no need to determine NumberFormatInfo ? Best Regards, Reza Shojaee
-
Thank you for your guidance, I test your solution and get appropriate result. But do you know why in the previous no need to determine NumberFormatInfo ? Best Regards, Reza Shojaee
I presume in your computer's language settings it's expecting a comma for a decimal seperator (2,00) rather than a period (2.00) Invariant Culture just tells the language to always use "."
-- Help me! I'm turning into a grapefruit! Buzzwords!
-
Thank you for your guidance, I test your solution and get appropriate result. But do you know why in the previous no need to determine NumberFormatInfo ? Best Regards, Reza Shojaee
I suspect that maybe the install of Delphi may have triggered a change in your localization settings, or maybe a windows update? I can't be sure this is the case, though. I haven't run into a situation where my locale has changed without my intervention. Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
-
Hi My Friends I develop software with C#.Net 2005, Yesterday installed Borland Delphi 2006 on my PC for debugging and working another program, Delphi work correct and no problem but when switch to C#, see Runtime Error about float.Parse method. For example if you write float f = float.Parse("2.3"); See below Runtime Error : Input string was not in a correct format. This method work in the previous and at now work on the another PC, I think System library conflict with delphi.:confused: If you have solution for me, I will grateful from you. Best Regards, Reza Shojaee
Usually the bug is in the
Human.Parse
method. ;)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke