---
title: "Apply Custom Formatting to Fields in C++"
---

Sometimes users need to apply custom formatting to fields. In this article, we will look at a couple of examples of how this can be done.

To learn more options, see the full list of properties for each field type in the corresponding class in the [Fields namespace](https://reference.aspose.com/words/cpp/namespace/aspose.words.fields).

## How to Apply Custom Formatting to Field Result

Aspose.Words provides API for custom formatting of field's result. You can implement [IFieldResultFormatter](https://reference.aspose.com/words/cpp/aspose.words.fields/ifieldresultformatter/) interface to control how the field result is formatted. You can apply numeric format switch, i.e. \# "#.##", date/time format switch, i.e. \@ "dd.MM.yyyy", and number format switch, i.e. \* Ordinal.

The following code example shows how to apply custom formatting for the field result:

{{< gist "aspose-words-gists" "d55d8631947d283b1f0da99afa06c492" "cpp-Programming-Documents-Fields-FormatFieldResult-FormatFieldResult.cpp" >}}

{{< gist "aspose-words-gists" "d55d8631947d283b1f0da99afa06c492" "cpp-Programming-Documents-Fields-FieldResultFormatter-FieldResultFormatter.cpp" >}}

## How to evaluate `IF` condition

If you want to evaluate `IF` condition after mail merge, you can use the [EvaluateCondition](https://reference.aspose.com/words/cpp/aspose.words.fields/fieldif/evaluatecondition/) method that immediately returns the result of the expression evaluation.

The following code example shows how to use this method:

{{< gist "aspose-words-gists" "d55d8631947d283b1f0da99afa06c492" "cpp-Programming-Documents-Fields-EvaluateIFCondition-EvaluateIFCondition.cpp" >}}

## How to Apply Custom Formatting to Time Field

By default Aspose.Words updates `TIME` field with current culture short time format. If you want to format the `TIME` field according to your requirement, you can achieve this by implementing [IFieldUpdateCultureProvider](https://reference.aspose.com/words/cpp/aspose.words.fields/ifieldupdatecultureprovider) interface.

The following code examples shows how to apply custom formatting to the `TIME` field:

{{< gist "aspose-words-gists" "d55d8631947d283b1f0da99afa06c492" "cpp-Programming-Documents-Fields-FieldUpdateCulture-FieldUpdateCultureProvider.cpp" >}}

{{< gist "aspose-words-gists" "d55d8631947d283b1f0da99afa06c492" "cpp-Programming-Documents-Fields-FieldUpdateCulture-FieldUpdateCultureProviderGetCulture.cpp" >}}

------

## FAQ

1. **Q:** How can I apply a numeric format (e.g., two decimal places) to a field result?
   **A:** Implement the `IFieldResultFormatter` interface and, in the `FormatResult` method, use a numeric format string such as `"#.##"` to format the value. Assign your formatter to `Document.FieldOptions.FieldResultFormatter` before calling `Document.UpdateFields()`.

2. **Q:** What is the easiest way to format a DATE field with a custom pattern like `dd.MM.yyyy`?
   **A:** You can either include the date format switch directly in the field code (`\@ "dd.MM.yyyy"`), or implement `IFieldResultFormatter` and return the formatted string for `FieldDate` types.

3. **Q:** How do I change the culture used by the TIME field so it displays a specific time format?
   **A:** Implement the `IFieldUpdateCultureProvider` interface and return a `CultureInfo` object that defines the desired time format. Set this provider on `Document.FieldOptions.FieldUpdateCultureProvider` before updating fields.

4. **Q:** Will my custom field formatter work with fields generated by a mail‑merge operation?
   **A:** Yes. After performing `Document.MailMerge.Execute`, assign the custom `IFieldResultFormatter` and then call `Document.UpdateFields()`; the formatter will be invoked for each field result.

5. **Q:** My custom formatter is not being called for a particular field-what could be wrong?
   **A:** Ensure that the formatter is assigned to `Document.FieldOptions.FieldResultFormatter` **before** you call `UpdateFields`. Also verify that the field type is supported by the formatter and that no other code resets the formatter after you set it.