簡體   English   中英

將字符串值轉換為浮點值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM