novaleaf
novaleaf
CC#
Created by novaleaf on 10/18/2024 in #help
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
6 replies
CC#
Created by novaleaf on 12/4/2022 in #help
❔ Tersest way to get (up to) last 3 elements in an array? (source array may have less than 3 items!)
Hello, trying to do something "simple", splitting a path string by \ and getting the last 3 folders:
var localFolders = filePath.Split('\\')[^3..];
var localFolders = filePath.Split('\\')[^3..];
The problem is this doesn't work if the Split() returns an array less than 3 long. I get an out of range exception) Is there some very terse work around that will get me the last 3 elements (or up to 3) of an array?
5 replies