How to use Application.FixedDecimalPlaces in the xlwings API way

The Application.FixedDecimalPlaces property in Excel is a global setting that controls whether Excel automatically rounds numbers entered into cells to a fixed number of decimal places. When enabled, it applies to all data entry across the workbook until the setting is turned off. This feature is primarily used for rapid data entry where consistent decimal precision is required, such as in financial or inventory systems, without manually formatting each cell. It is important to note that this setting affects only new entries and does not alter existing cell values or their display formatting.

In the xlwings API, which provides a programmatic interface to Excel’s object model from Python, you can access and manipulate the Application.FixedDecimalPlaces property. The syntax for using this property is straightforward, as it corresponds directly to the Excel object model. The property can be set to an integer to specify the number of decimal places or to False to disable the fixed decimal rounding.

Syntax in xlwings:

app = xw.apps.active # Get the active Excel application instance
app.api.FixedDecimalPlaces = places
  • places: An integer that specifies the number of decimal places to fix. The value must be between -15 and 15, inclusive. Setting places to a positive number (e.g., 2) rounds entered numbers to that many decimal places. Setting it to 0 rounds to the nearest integer. Setting it to a negative number (e.g., -2) rounds to the nearest hundred. To turn off the fixed decimal setting, assign False to the property.

Parameter Details:

Value TypeDescription
IntegerSets the fixed decimal places to the specified number (range: -15 to 15).
BooleanUse False to disable fixed decimal rounding; True is not a valid input.

Example Usage:
Below are practical xlwings code examples demonstrating how to use the FixedDecimalPlaces property in different scenarios.

  1. Enable Fixed Decimal Rounding to Two Places:
    This example activates the fixed decimal feature, setting it to round all new numeric entries to two decimal places. It is useful for standard currency inputs.
import xlwings as xw
app = xw.apps.active
app.api.FixedDecimalPlaces = 2
# Now, entering 123.456 in any cell will be stored as 123.46
  1. Disable Fixed Decimal Rounding:
    To turn off the fixed decimal setting, set the property to False. This reverts Excel to its normal data entry behavior.
import xlwings as xw
app = xw.apps.active
app.api.FixedDecimalPlaces = False
# New entries will no longer be automatically rounded
  1. Round to Nearest Hundred (Negative Decimal Places):
    Using a negative value allows rounding to powers of ten. Here, setting -2 rounds entries to the nearest hundred.
import xlwings as xw
app = xw.apps.active
app.api.FixedDecimalPlaces = -2
# Entering 1234 will be stored as 1200
  1. Check Current Fixed Decimal Setting:
    You can also retrieve the current value of the property to inspect the setting.
import xlwings as xw
app = xw.apps.active
current_setting = app.api.FixedDecimalPlaces
print(f"Current fixed decimal places: {current_setting}")
# Output might be 2, -1, or False if disabled

June 10, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *