I have an object with a float property that I want to place into a text field. The problem is, that if I normally transform it with ".ToString()" it is written with scientific notation i. e. "1.5E+07" (And it cuts of all my decimal points). Because of that I wanted to transform it with the optional number parameter "#" and so I wrote ".ToString("0." + new string('#', 339)" to guarantee that it only cuts the useless zeros from my float, but writes all other numbers. No matter whether I use that or just "0.###" it always cuts all my decimal numbers. I. e. "-3740295.25" (float) turns into "-3740295" (string).
I really don't understand why this is happening and didn't find anything similar on the internet and most conversion are about doubles to strings anyway(which also doesn't work for me).
EDIT:
As requested here is a code snippet, which made me realize, if I create a completely fresh float it just works, I don't know why it doesn't work with the float from the object:
float testFloat1 = 1234.5544f;
float testFloat2 = (keyValuePair.Value as JsonFloat).Property; // -3740295.25
string testString1 = testFloat1.ToString("0.###"); // 1234.554
string testString2 = testFloat2.ToString("0.###"); // -3740295
This is the object in short:
public partial class JsonFloat : JsonValue
{
public float Property { get; set; }
public JsonFloat(float property)
{
Property = property;
}
}
Kind Regards