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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    Author
    Topic
    #406041

    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!

    Viewing 1 reply thread
    Author
    Replies
    • #838888

      What happens if you omit the number picture switch altogether?

      • #839136

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

        • #839188

          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.

          • #839239

            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 smile

          • #839240

            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 smile

        • #839189

          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.

        • #839436

          Hi Chris,
          [indent]


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


          [/indent]
          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
          [Fmr MS MVP - Word]

          • #839964

            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! thankyou

          • #839965

            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! thankyou

        • #839437

          Hi Chris,
          [indent]


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


          [/indent]
          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
          [Fmr MS MVP - Word]

      • #839137

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

    • #838889

      What happens if you omit the number picture switch altogether?

    Viewing 1 reply thread
    Reply To: Suppressing trailing zeros in a Mergefield result (Word 2000 SR-1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: