Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Aug 2002
    Location
    Harrisburg, Pennsylvania, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    Is it possible to delete trailing zeros from the end of a number merged into a mergefield, when one doesn't know ahead of time how many zeros there may be? I know it's possible to use a numeric picture switch (#) to cut off numbers at any given decimal place, but I need to format the field so that, for example:

    4.000 will appear as 4
    4.200 will appear as 4.2
    4.250 will appear as 4.25
    4.258 will appear as 4.258

    The number is in the middle of a paragraph, so using # in a numeric switch is difficult, because of the spaces it will leave behind. Also, this document is used as part of a batch merge process, so I can't merge the doc. and then fiddle with it after the fact -- the formatting has to be right when the document is merged.

    It seems to me this should be possible, but I've never found a way to do it -- am I missing something?

    Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    What happens if you omit the number picture switch altogether?

  3. #3
    Lounger
    Join Date
    Aug 2002
    Location
    Harrisburg, Pennsylvania, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    It brings in however many decimal places there are in the data file, including any trailing zeros, unfortunately.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    What is your data source? If you're using a query, you probably can build this into the query. If you're picking up text that has been output that way, or picking up formatting from an Excel column, I'm not sure. I'd know how to do it with VBA (for text, convert to number and back to string), but I'm not that facile with fields.

  5. #5
    Lounger
    Join Date
    Aug 2002
    Location
    Harrisburg, Pennsylvania, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    The data source is a text file created by a Visual FoxPro application. We can probably fix the problem in VFP, have the extra zeros lopped off there before it creates the merge data file, but I was hoping I could save some time and work by just fixing it in the Word doc. (I don't work with VFP, so I will have to get someone else to make any changes there). Thanks for the hint about VBA, though, I do occasionally get to do some programming with that -- may come in handy at some point <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    Hi Chris,
    <hr>It brings in however many decimal places there are in the data file, including any trailing zeros<hr>
    That doesn't sound right for a mergefield that inports numbers. For example,
    {=1.23450000} only shows 1.12345

    If your merge data is importing the number as a string, perhaps putting it inside an equation will do the trick, eg:
    {={MERGEFIELD Data}}

    Cheers
    PS: You could always use a brute-force field:
    {QUOTE{SET Data {MERGEFIELD Source}}{=IF(MOD(Data,1)=0,{=Data # 0},IF(MOD(Data,1.1)=0,{=Data # 0.0},IF(MOD(Data,1.11)=0,{=Data # 0.00},IF(MOD(Data,1.111)=0,{=Data # 0.000},{=Data # 0.0000}))))}}
    Beyond the 4 decimal, though, the field gets too complex for Word
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #7
    Lounger
    Join Date
    Aug 2002
    Location
    Harrisburg, Pennsylvania, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    Success! Wrapping my mergefield inside an { = } field does the trick. I hadn't thought of it in those terms, that Word was interpreting my "number" as a string, but it appears that's what was happening. The equation field is a wonderfully simple solution.

    Thanks to all for your suggestions! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •