Inside an MS Word Template, I’m attempting to display just the whole number/integer if the decimal is zero. For example, instead of 10.0, just show 10. If the value is 10.6, display it as is… 10.6. Thus far, I haven’t discovered the syntax to make it work. I’m expecting I can use an IF statement and MODULUS, but I can’t seem to get the syntax right. Not even sure that is the right approach. Any help is appreciated.
@JeffKing Could you please attach your sample input, output and expected output documents here for our reference? We will check the issue and provide you more information.
Input is a dataset from a SQL Database - Example values would be “2.60”, “97.40”, “10.00”, “90.00”.
“2.60” should return “2.6”
“10.00” should return “10”
I am unable to share the document as it is private customer data.
This is the field code I’m using, and it’s essentially working (kind of). I can force the condition to display value as desired, but I cannot figure out how to determine if the decimal place is a zero value.
In this example, I’m toggling between greater than and less than zero to test only:
{ IF { MERGEFIELD MyPercent } > 0 { MERGEFIELD MyPercent \# "##.0;0" \* MERGEFORMAT } \# "##;0" }
I’m somewhat of a rookie in field codes and using the above syntax - would love to find a definitive source to gain a better understanding of how to manipulate these “field codes”.
@JeffKing You can use condition like this:
{ IF "{=INT({MERGEFIELD MyPercent})}" = "{MERGEFIELD MyPercent}" {MERGEFIELD MyPercent \# "0"} {MERGEFIELD MyPercent \# "##.0"} }
That worked amazingly. I left out the quotation marks, as it wasn’t exactly what I expected with it. Once removed, it worked perfectly. What purpose do the quotes serve?
I’m referring to the quotes like these "{=INT({MERGEFIELD MyPercent})}"
Thank so much for the quick and simple solution.
@JeffKing Double quotes are required if field value contains whitespaces. For example original field might look like this:
{ IF {MERGEFIELD test} = value true false }
If test
field has value with whitespace, the result will be the following:
{ IF value with whitespace = value true false }
Which is not valid IF field syntax.