Porter generally prefers format strings to manual text concatenation, though he admits printf conversion tokens don't always stick in memory.
myField.DataFormatString = "{0:#,##0." + new string('0', 2) + ";(#,##0." + new string('0', 2) + ")}";Jasmine's co-worker wanted configurable decimal places. The solution joins two calls to `new string('0', 2)` in `myField.DataFormatString`. The result formats grouped numbers with two fractional digits and wraps negative values in parentheses. Porter accepts the intent but suggests extracting the repeated fragment to a `decimalPlaces` variable first.
While reviewing .NET documentation for custom numeric formats, Porter discovered the per-mille specifier requires the Unicode sign U+2030—awkward to type on most keyboards. A line like `string perMilleFmt = "#0.## " + '\u2030';` crosses into TRWTF territory.




Comments
No comments yet — be the first.
Open the discussion
No account or password needed — just enter your e-mail and we’ll send you a one-time sign-in link. First time here? You’re set up automatically.
Your rating will be applied automatically after you sign in.
Check your inbox
We’ve sent a sign-in link to …. Open it on this device — this tab will sign you in automatically.
Nothing arrived? Check your spam folder — and mark the mail as "Not spam" so it lands in your inbox next time.