L
Larry Lard
I am trying to apply the following easy-to-state formatting rule to
display a number:
- If the number is positive or negative, display it in the 'default'
way
- If the number is zero, the output should be an empty string
Now I know this is trivial to code, but the elegant solution would be
passing a custom format string to ToString(). The problem is, I can't
make one that works: There doesn't seem to be a way to combine the
'pre-defined' numeric formats with the user-defined format idea of
semi-colon-delimited differing formats for positive;negative;zero
inputs.
I tried "#########.######;-######.#####;" which *almost* works, except
that for whole-number inputs it still displays a decimal point. There
doesn't seem to be a 'conditional decimal point' formatting character
in the same way that # is a 'conditional digit' formatting character.
As I said, this isn't desperately important, but I would be interested
to learn if I am missing something.
display a number:
- If the number is positive or negative, display it in the 'default'
way
- If the number is zero, the output should be an empty string
Now I know this is trivial to code, but the elegant solution would be
passing a custom format string to ToString(). The problem is, I can't
make one that works: There doesn't seem to be a way to combine the
'pre-defined' numeric formats with the user-defined format idea of
semi-colon-delimited differing formats for positive;negative;zero
inputs.
I tried "#########.######;-######.#####;" which *almost* works, except
that for whole-number inputs it still displays a decimal point. There
doesn't seem to be a 'conditional decimal point' formatting character
in the same way that # is a 'conditional digit' formatting character.
As I said, this isn't desperately important, but I would be interested
to learn if I am missing something.