Forums » C# Framework » BUG: float.Parse and regional settings »
| Evgeniy Rojkov | BUG: float.Parse and regional settings | ||
|---|---|---|---|
|
Added by Evgeniy Rojkov about 1 year ago
Some regional setting use comma as decimal separator. This lead to exception in float.Parse and other number parsing from strings. My solution code¶
public static float FloatParse(string value)
{
return float.Parse(value.Replace(",", "."), CultureInfo.InvariantCulture);
}
Here exception details¶
System.FormatException was unhandled
Message=FormatException
StackTrace:
at System.Single.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.Single.Parse(String s)
at cocos2d.CCParticleSystem.initWithDictionary(Dictionary`2 dictionary)
at cocos2d.CCParticleSystem.initWithFile(String plistFile)
code:
m_tStartColor.r = float.Parse(ChangeToZeroIfNull(valueForKey("startColorRed", dictionary)));
|
||
| Evgeniy Rojkov | RE: BUG: float.Parse and regional settings | ||
|
Added by Evgeniy Rojkov about 1 year ago
same bug with |
||
| Raghu S | RE: BUG: float.Parse and regional settings | ||
|
Added by Raghu S about 1 year ago
hi,
int.Parse("5");
will work but
int.Parse("5.0252"); will throw a format exception
in your case you should use
double.Parse("5.0252");
|
||
| Evgeniy Rojkov | RE: BUG: float.Parse and regional settings | ||
|
Added by Evgeniy Rojkov about 1 year ago
i just reporting bugs, i dont need solutions. already commited fix in local git repository. int.Parse("5.0252", NumberStyles.AllowDecimalPoint); int.Parse("5.0252", NumberStyles.AllowDecimalPoint); |
||
| RongHong Huang | RE: BUG: float.Parse and regional settings | ||
|
Added by RongHong Huang about 1 year ago
hi , Evgeniy Rojkov, |
||
| Evgeniy Rojkov | RE: BUG: float.Parse and regional settings | ||
|
Added by Evgeniy Rojkov about 1 year ago
i dont care about comma or dot thing.
throw FormatException. cocos2d parse particles settings from *.plist and use alot of float.parse and int.parse in CCParticleSystem.cs you can view this error, change regional settings to russian in emulator and run cocos default "tests" -> "particles". |
||
| Evgeniy Rojkov | RE: BUG: float.Parse and regional settings | ||
|
Added by Evgeniy Rojkov about 1 year ago
Here my fix for CCParticle.initWithDictionary Parse error keep throwing in Russian WPes. |
||
| Evgeniy Rojkov | RE: BUG: float.Parse and regional settings | ||
|
Added by Evgeniy Rojkov about 1 year ago
|
||
| Evgeniy Rojkov | RE: BUG: float.Parse and regional settings | ||
|
Added by Evgeniy Rojkov about 1 year ago
in new master from 17.04.2012 12:25:35
System.FormatException was unhandled
Message=FormatException
StackTrace:
at System.Single.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.Single.Parse(String s)
at cocos2d.CCSpriteFrameCache.addSpriteFramesWithDictionary(Dictionary`2 pobDictionary, CCTexture2D pobTexture)
at cocos2d.CCSpriteFrameCache.addSpriteFramesWithFile(String pszPlist)
at tests.SpriteFrameTest..ctor()
at tests.SpriteTestScene.createSpriteTestLayer(Int32 nIndex)
at tests.SpriteTestScene.nextSpriteTestAction()
at tests.SpriteTestDemo.nextCallback(CCObject pSender)
at cocos2d.CCMenuItem.activate()
at cocos2d.CCMenu.ccTouchEnded(CCTouch touch, CCEvent ccevent)
at cocos2d.CCTouchDispatcher.touches(List`1 pTouches, CCEvent pEvent, Int32 uIndex)
at cocos2d.CCTouchDispatcher.touchesEnded(List`1 touches, CCEvent pEvent)
at cocos2d.CCApplication.ProcessTouch()
at cocos2d.CCApplication.Update(GameTime gameTime)
at Microsoft.Xna.Framework.Game.Update(GameTime gameTime)
at tests.Game1.Update(GameTime gameTime)
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
at Microsoft.Xna.Framework.GameHost.OnIdle()
at Microsoft.Xna.Framework.MobileGameHost.RunOneFrame()
at Microsoft.Xna.Framework.MobileGameHost.gameLoopTimer_Tick(Object sender, EventArgs e)
at Microsoft.Xna.Framework.DispatcherTimerWin32.TimerElapsed(IntPtr hWnd, UInt32 uMsg, IntPtr nIDEvent, UInt32 uTime)
i know my english is bad. |
||
| Evgeniy Rojkov | RE: BUG: float.Parse and regional settings | ||
|
Added by Evgeniy Rojkov about 1 year ago
another locale problem http://www.cocos2d-x.org/boards/17/topics/11221 |
(1-9/9)
