Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does the Standard Numeric Format for percentages include a space?
    text
    copied!<h2>The Back Story</h2> <p>I have some decimal values which I am displaying as strings on a web page as part of a larger string. I started off using a Standard Numeric Format String to output this. E.g.</p> <pre><code>myDecimal.ToString("P0") </code></pre> <p>The <code>0</code> after the <code>P</code> tells it I want no decimal places. This works as far as it goes, in that my ouput ends up looking something like: </p> <blockquote> <p>Calculated as above based on the phased minimum Company contribution rate of 2 %</p> </blockquote> The Space Problem <p>I really want to get rid of that space between the number and the percentage sign as in some cases it ends up splitting across lines. And also, I prefer the % to butt up to the number.</p> <h2>Possible Workarounds</h2> 1. html / css solution <p>I could put a <code>&lt;nobr&gt;</code> tag or a <code>&lt;span style="white-space: nowrap;"&gt;</code> around it. But, that feels awkward, and anyway I prefer the % to butt right up to the number as I think it looks better. It's how we would write it in reports in this neck of the woods, so it's how I want it on the web page.</p> 2. Custom format string <p>I am going to end up using a Custom Numeric Format String, E.g.</p> <pre><code>myDecimal.ToString("0%") </code></pre> <h2>The Question</h2> <p>Is it more common to display percentages with a space between the number and the percentage sign? This would surprise me, but it could be.</p> <p>Is there a way to tell the <strong>Standard Numeric Format String</strong> I don't want the space?</p> <p>Is there any disadvantage to using a <strong>Custom Numeric Format String</strong> over a <strong>Standard Numeric Format String</strong>?</p> <p>Ok - I admit it, that was more than one question - Extra Credit if you answer them all.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload