Skip to content

Allow setting number of decimals in edd_format_discount_rate() #9819

Description

@goncalovf

Enhancement Request

Explain your enhancement (please be detailed)

Add a third parameter to edd_format_discount_rate() and pass it to edd_format_amount(). This would allow us to format discount rates without decimals. Something like:

/**
 * Format Discount Rate
 *
 * @since 1.0
 * @param string     $type Discount code type
 * @param string|int $amount Discount code amount
 * @param string     $decimals Default true. Whether or not to use decimals.
 * @return string $amount Formatted amount
 */
function edd_format_discount_rate( $type = '', $amount = '', $decimals = true ) {
	return ( 'flat' === $type )
		? edd_currency_filter( edd_format_amount( $amount, $decimals ) )
		: edd_format_amount( $amount, $decimals ) . '%';
}

Justification or use case

We show discount percentages as "10%", not "10.00%".

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions