I’m writing some debug system in a job and I need to format a number to only include two decimal places. It would seem like the FixedString64Bytes AppendFormat would allow that but I find that id does not allow me to pass a float and because it needs to be convertable to INativeList.
The type ‘float’ must be convertible to ‘Unity.Collections.INativeList’ in order to use it as parameter ‘T0’ in the generic method ‘FormatError Unity.Collections.FixedStringMethods.AppendFormat<T,U,T0>(this ref T, in U, in T0)’
Is this just meant to format strings? The docs are being quite unhelpful and have no examples.
Is there a sane way to format a float and append it to fixed string?
I haven’t used the FixedString API, but can you just create the string with floatValue.ToString(“F2”) and pass the result?
You can’t create string literals inside a burst job as they are managed objects. There does not seem to be any nice ways of formatting numbers to strings with modifiers. I ended up using a very manual approach. Perhaps I’ll abstract it into a static parametric function if I need to do more of this.
int score = (int)math.round(behaviors[i].Score * 100);
label.Append(score / 100);
score %= 100;
label.Append(Dot);
label.Append(score / 10);
score %= 10;
label.Append(score);
this did the trick since my numbers are in the 0-1 range. Dot is a static readonly fixed string
private static readonly FixedString32Bytes Dot = ".";