[英]Converting string value to float value
在我的代码中,我将字符串值转换为浮点值。 在我的代码中: guns - array(size = 5) 和 Chargunsinformations - string value。
guns[gunsNum] = float.Parse(ChargunsInformation);
Unity 给了我一个错误:
FormatException: 输入字符串的格式不正确。 System.Number.ParseSingle(System.String 值,System.Globalization.NumberStyles 选项,System.Globalization.NumberFormatInfo numfmt)(在 <437ba245d8404784b9fbab9b439ac908>:0) System.Single.Parse(System.String s,System.Globalization.NumberStyles , System.Globalization.NumberFormatInfo info) (at <437ba245d8404784b9fbab9b439ac908>:0) System.Single.Parse (System.String s, System.IFormatProvider 提供者) (at <437ba245d8404784b9fbab90.00000000000000:00) ) (at <437ba245d8404784b9fbab9b439ac908>:0) StartOfAllScript.Update () (at Assets/Scripts/Player Scripts/StartOfAllScript.cs:35)
请帮我。 我试图解决这个问题 2 个小时。
我想问题与您的系统文化有关。 请尝试以下代码片段
guns[gunsNum] = float.Parse(ChargunsInformation, CultureInfo.InvariantCulture);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.