You could use a compound field coded as:
{QUOTE{SET Val {MERGEFIELD MyField}}{IF{=INT(Val) # 0.00}= {REF Val} {=INT(Val) # $,0} {=Val # $,0.00}}}
where 'MyField' is your mergefield's name.
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required.