Edit: I solved this by using a picture switch.
{ IF { MERGEFIELD OurFileNumber } = "{ Mergefield OurFileNumber \# 0 }" { MergeField OurFileNumber \# 0 } { MergeField OurFileNumber \# 0.0 } }
Works.
See also Paul Edstein's simpler construction:
{={=INT({MERGEFIELD OurFileNumber}) \# 0}+{=MOD({MERGEFIELD OurFileNumber},1) \# "0.0;;0"}}
He provides useful links below, as well.
Hi, I am trying to assist someone with a merge question. He wants a mergefield to show as an integer without any decimal point if it is an integer and to show with a decimal point and one decimal if not an integer. I've been working on the test for an Integer using either the INT or the ROUND functions without success.
I expected this to be simple but am stymied.
I know I need to work more on the decimal format, but currently Round to 0 decimals is giving something different from the original as is INT.
Here are the field results:
I am going to refer to Paul Edstein's Field Maths Tutorial to try to figure this out.
https://www.msofficeforums.com/word/387 ... orial.html
I am already seeing that I may want to simply use a picture switch to do the comparison.
Here is a field with a picture switch instead of the functions and it seems to be working.
{ IF "{ MERGEFIELD OurFileNumber }" = "{ Mergefield OurFileNumber \# 0 }" "Truetext" "FalseText" }
{ IF { MERGEFIELD OurFileNumber } = "{ Mergefield OurFileNumber \# 0 }" { MergeField OurFileNumber \# 0 } { MergeField OurFileNumber \# 0.0 } }
This works. Thank you again, Paul.
Here is the original question in case someone wants to weigh in directly:
https://answers.microsoft.com/en-us/mso ... e2e9ed2b82
Test mergefield to see if it is an Integer - differential formatting
-
- 5StarLounger
- Posts: 621
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Test mergefield to see if it is an Integer - differential formatting
You do not have the required permissions to view the files attached to this post.
Last edited by Charles Kenyon on 08 Apr 2022, 16:28, edited 2 times in total.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- Administrator
- Posts: 78534
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Test mergefield to see if it is an Integer - differential formatting
Glad to see you were able to solve it.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Test mergefield to see if it is an Integer - differential formatting
Simpler:
{={=INT({MERGEFIELD OurFileNumber}) \# 0}+{=MOD({MERGEFIELD OurFileNumber},1) \# "0.0;;0"}}
{={=INT({MERGEFIELD OurFileNumber}) \# 0}+{=MOD({MERGEFIELD OurFileNumber},1) \# "0.0;;0"}}
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- 5StarLounger
- Posts: 621
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Test mergefield to see if it is an Integer - differential formatting
Thank you Paul. I see you posted this in the original thread as well and know that the OP appreciates it.
I have never found good documentation on Word's functions. Perhaps I have not looked hard enough.
I have never found good documentation on Word's functions. Perhaps I have not looked hard enough.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Test mergefield to see if it is an Integer - differential formatting
The solution I posted is really just a matter of figuring out how to exploit fully documented field switches and a bit of math to achieve the desired outcome.
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- 5StarLounger
- Posts: 621
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Test mergefield to see if it is an Integer - differential formatting
I'm glad it is easy for someone. Again, I have never found good documentation on Word functions. I tried both INT and MOD before going to my more complex solution.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Test mergefield to see if it is an Integer - differential formatting
No one said it's easy...
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- 5StarLounger
- Posts: 621
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Test mergefield to see if it is an Integer - differential formatting
You've said this is well documented. Any chance of a link to the documentation?
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Test mergefield to see if it is an Integer - differential formatting
See, for example:
https://support.microsoft.com/en-us/off ... 8c94aa19f4
https://support.microsoft.com/en-us/off ... 36ae43508c
All my solution has done is to use the documented field switches creatively. You'll find more of that in my Microsoft Word Field Maths Tutorial, available at:
https://www.msofficeforums.com/word/387 ... orial.html
or:
http://www.gmayor.com/downloads.htm#Third_party
https://support.microsoft.com/en-us/off ... 8c94aa19f4
https://support.microsoft.com/en-us/off ... 36ae43508c
All my solution has done is to use the documented field switches creatively. You'll find more of that in my Microsoft Word Field Maths Tutorial, available at:
https://www.msofficeforums.com/word/387 ... orial.html
or:
http://www.gmayor.com/downloads.htm#Third_party
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- 5StarLounger
- Posts: 621
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Test mergefield to see if it is an Integer - differential formatting
Thank you.
I've used and very much appreciate your tutorials.
I am talking about INT, MOD, ABS, etc.
I see now that you discuss these in your Word Field Maths Tutorial on Page 4. I had forgotten.
I've used and very much appreciate your tutorials.
I am talking about INT, MOD, ABS, etc.
I see now that you discuss these in your Word Field Maths Tutorial on Page 4. I had forgotten.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: Test mergefield to see if it is an Integer - differential formatting
If you go to: https://support.microsoft.com/en-us/off ... b74aabb6b2,
then click on '= (Formula) field', that will open up: https://support.microsoft.com/en-us/off ... fc2b5bc21d
which has all the available Operators, Functions, Picture Switch details, etc.
then click on '= (Formula) field', that will open up: https://support.microsoft.com/en-us/off ... fc2b5bc21d
which has all the available Operators, Functions, Picture Switch details, etc.
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- 5StarLounger
- Posts: 621
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Test mergefield to see if it is an Integer - differential formatting
Thank you, again.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word