Format string decimal point problem

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.
 
C

Cor Ligthert

Larry,

You mean that you make work from
\\\
a = ""
if b <> 0 then a = b.tostring
///

I never take the time to think about those things to much

I check the characters I have to type for that mostly to see what I take.

:)

Cor
 
C

C-Services Holland b.v.

Cor said:
Larry,

You mean that you make work from
\\\
a = ""
if b <> 0 then a = b.tostring
///

That doesn't insert the thousand seperators he wants AFAIK
 
L

Larry Lard

Cor said:
Larry,

You mean that you make work from
\\\
a = ""
if b <> 0 then a = b.tostring
///

I never take the time to think about those things to much

I do :) Elegance above all else!
 
C

C-Services Holland b.v.

Cor said:
Sorry,

Has not a culture

:)

Cor

Luckily I'm not from Friesland, only my name is :p

Anyhow, I haven't played around with the culture settings that's why I
added the AFAIK (As Far As I Know). I guess I'll have to look into that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top