Display max 3 characters of number
<p>I have a number at range <code>1</code> to <code>999</code>.</p>

<p>I want <code>1</code> through  <code>&lt;10</code> to display a single decimal, if significant. But <code>10</code> through <code>999</code> should not display decimals at any time:</p>

<pre><code>float[] testNums = { 2f, 3.4f, 7.59f, 22f, 37.3f, 104f, 351.7f };

string[] output = new string[testNums.Length];
for (int i = 0; i &lt; testNums.Length; i++) {
    string strNum = testNums[i].ToString("0.#"); //"0.#" is the closest I've found
    output [i] = strNum;
}
Debug.Log(string.Join(", ", output));
</code></pre>

<p>Result: <code>2, 3.4, 7.6, 22, 37.7, 104, 351.7</code></p>

<p>Desired result: <code>2, 3.4, 7.6, 22, 37, 104, 351</code></p>

<p>Is there a way to achieve this only with <a href="https://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.100).aspx" rel="nofollow">number formats</a>, or will I have to write code for it? (e.g.:)</p>

<pre><code>if(strNum.Length &gt;= 4)
{
    strNum = strNum.Substring(0,3).TrimEnd('.', ',');
}
</code></pre>