Skip to main content
Easy Digital Downloads Documentation
Documentation, Reference Materials, and Tutorials for Easy Digital Downloads

Changing the Number of Decimals in Prices

Easy Digital Downloads defines two decimal points as the default for product pricing. This is applicable for the majority of eCommerce stores, however there are definitely situations in which a different number of decimals is required. For these situations, a little bit of code is necessary to override the default value:

function kjm_edd_use_three_decimals() {
    return 3;
}
add_filter( 'edd_sanitize_amount_decimals', 'kjm_edd_use_three_decimals' );
add_filter( 'edd_format_amount_decimals', 'kjm_edd_use_three_decimals' );

The number “3” in this snippet can be changed to any number required, including zero.

This code can be inserted into either a custom plugin or a child theme’s
functions.php file. If this is your first time creating a custom plugin, Pluginception can be very helpful as it makes the process of generating a new plugin much simpler.

What this code changes

When this snippet is active on a site, all download prices will always appear with the defined number of decimals. For example, changing the number of decimals to “3” like in the example above will result in prices on the download edit screen appearing like this:

If download prices are saved with a number of decimals that is greater than the number allowed by either the default value or the value overridden by the snippet above, the result upon updating the download will be a number rounded to the correct number of decimals. For example if the number of decimals is set to “1” and a download’s price gets entered as $1.49, after saving the download, the price will be updated to $1.5.

Read our latest blog post:
NEW: Bulk Generate, Save & Export Invoices