BigInteger.ToString("F") giving Format Exception
This is the exception i am getting while running the code:
FormatException: format 'F' not implemented System.Numerics.BigInteger.ToString (System.String format, IFormatProvider provider) System.Numerics.BigInteger.ToString (System.String format) GameManager.Start () (at Assets/Scripts/GameManager.cs:38)
Here is my code:
using UnityEngine;
using System.Collections;
using System.Numerics;
using Mono.Math;
public class GameManager : MonoBehaviour {
System.Numerics.BigInteger mynumber = System.Numerics.BigInteger.Parse("18000000000000000000000000000000000001" );
void Start () {
mynumber.ToString ("F" );
}
}
Please Help, what i am doing wrong.
Please edit your question, select the code, and press the 101010 button to format it properly.
The error message seems pretty clear - "format F is not implemented".
@Dave Carlile can u explain little bit i have imported system.numeric.dll to implement biginterger.
where do i find that F ?
Answer by Bunny83 · Jun 01, 2016 at 01:44 PM
Well, the error couldn't be much clearer:
format 'F' not implemented System.Numerics.BigInteger.ToString
So you can't use the format F. Actually it looks like the Mono implementation of BigInteger doesn't support ToString with a custom format at all.
I'm not sure which verion of BigInteger Unity is actually using, however i've found an implementation that only supports "X", "G", "D", "x", "g", "d". The Mono.Math implemenation of BitInteger doesn't support ToString with a format string at all. Only ToString which takes a radix uint which defaults to "10".
The version of system.numeric.biginterger is 2.0.5.0 . if i change the version would it help?
As i said i haven't found a mono implementation that supports all the standard number formats. As you might know $$anonymous$$ono is a replica of $$anonymous$$icrosoft's .NET framework and some things are still missing or implemented differently. You might be able to copy a DLL from the .NET framework, but you should be careful about licensing issues if you do so.
Answer by HarshadK · Jun 01, 2016 at 01:39 PM
You might need to specify the CultureInfo as the second parameter to the ToString such as:
Using a CultureInfo object that is culture-independent:
mynumber.ToString ("F", CultureInfo.InvariantCulture);
or, English (United States) based CultureInfo object:
mynumber.ToString ("F", CultureInfo.CreateSpecificCulture("en-US"));
@Harshad$$anonymous$$ , It is not working i am getting the same Exception.
Your answer
Follow this Question
Related Questions
Error upon rebooting Unity - "Associated script cannot be loaded" How can I resolve this? 2 Answers
StartCoroutine error message in C# 1 Answer
Anchor a health bar to a character/enemy 3 Answers
How do I create a Continuous Turn in XR for my VR Rig instead of Snap Turn Provider? 0 Answers
ForcedScopedThreadAttach 0 Answers