Insert Formula with decimal points?

J

John Dempsey

In Word I am trying to format a number created from a formula,
examples below:

If 40.00 want to display no decimals so just 40
If 37.50 want to display just 37.5
If 37.75 want to display just 37.75

How do you do this. This looks a fairly easy task and I am probably
being completely stupid, but I cannot find out how to do this with
switches.

{ =({MERGEFIELD} + 0) \# "0.00" }

This adds 2 decimals no matter what.

Any ideas.

Cheers JED
 
G

Greg

John,

No easy task. \# 0.00 forces the zeroes whether they
should be there or not. \# 0.## eliminates the zeroes but
forces a decimal point "40." which looks odd. The
following is coded based on a number bookmarked as "Test"
and seems to work:

{ IF { REF Test } = { =INT({ REF Test}) }”{REF Test
\# “,0” }””{ REF Test \# “,0.###” }” }

Basically this is just comparing the value to the integer
of the value and if it matches it uses one format switch
and if not it uses another.
 
G

Greg

John,

I just looked at my first post in reply to your question
and it appears the speach marks were garbled.

Try:
 
J

John Dempsey

Hi guys been away for a while sorry about the delay. This is great I
will try tommorrow at work and let you know my results. Macropod I
havent tried that its coming out of a SQL database so I think the
database gives it the two decimals, I just need it reduced.

Thanks for all your help with this.

John
 
G

Graham Mayor

Plan B

You could use a conditional field to determine whether the decimal was 00 or
not and set the switch accordingly. There are probably several ways to do
this, but one which will work is:

{IF {=MOD({Mergefield Fieldname},1)} = 0 "{Mergefield Fieldname \#
",0;(0);"}" "{Mergefield Fieldname \# ",#.####;(,#.####)"}"}

If the field content is 0 this will display nothing. Otherwise
it will display up to four places of decimals with suppressed trailing zeros
and whole numbers will have comma thousand separators but no decimal point.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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