- Home /
how to limit character of text with c# scripting?
so there's a public text,
which is then converted ToDouble,
then used in an equation,
then converted back ToString again.
I want to limit length of that string to 5.
because it shows like 15 digits after decimal point.
which is pointless and also text gets out of its box,
cant find truncate horizontal overflow option.
did some googling and found math.round function,
but it only seems to work with floats and not with doubles or strings.
or may be Im using it incorrectly.
please help.
thank you.
Answer by Legend_Bacon · Aug 07, 2018 at 05:15 PM
Hello there,
You can do that during the conversion to string, by adding a formatter as an argument to your ToString() call.
If you want to truncate after 5 decimals, use yourValue.ToString("F5");
. Of course, you can replace the 5 with another number to truncate at a different point.
I'm also pretty sure this works with both floats and doubles, but you might want to double-check.
I hope that helps!
Cheers,
~LegendBacon
Your answer
Follow this Question
Related Questions
How do I set a maximum character limit to my textbox C#? 1 Answer
Character controller slope limit issues 1 Answer
Importing Animations to Unity from maya! 1 Answer
Simple character rotation 1 Answer
Animations 0 Answers