C
C#3mo ago
novaleaf

how to avoid "-0" when converting float to string?

when I convert floats to string like in this example, often I get "-0" as a value. Does anyone know a simple way to convert these to positive zero?
public static string _Serialize(this Vector3 value)
{
return $"{value.X}, {value.Y}, {value.Z}";
}
public static string _Serialize(this Vector3 value)
{
return $"{value.X}, {value.Y}, {value.Z}";
}
this is for serialization purposes, so I'd like to avoid some heavy checks just to avoid -0
3 Replies
velreine
velreine3mo ago
Math.Abs maybe?
novaleaf
novaleafOP3mo ago
i could just check ==0 but that's some special branching just for a single value so I'm wondering if there's something more graceful
sibber
sibber3mo ago
why is there a _Serialize method? but yeah id just check if -0 but according IEEblabla -0 and 0 arent the same thing
Want results from more Discord servers?
Add your server