You appear to be a bot. Output may be restricted
Description
Sanitize Amount
Returns a sanitized amount by stripping out thousands separators.
Usage
$string = edd_sanitize_amount( $amount );
Parameters
- $amount
- ( string ) required – Price amount to format
Returns
string $amount Newly sanitized amount
Source
File name: easy-digital-downloads/includes/formatting.php
Lines:
1 to 48 of 48
function edd_sanitize_amount( $amount ) { $is_negative = false; $thousands_sep = edd_get_option( 'thousands_separator', ',' ); $decimal_sep = edd_get_option( 'decimal_separator', '.' ); // Sanitize the amount if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { $amount = str_replace( $thousands_sep, '', $amount ); } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { $amount = str_replace( '.', '', $amount ); } $amount = str_replace( $decimal_sep, '.', $amount ); } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { $amount = str_replace( $thousands_sep, '', $amount ); } if( $amount < 0 ) { $is_negative = true; } $amount = preg_replace( '/[^0-9\.]/', '', $amount ); /** * Filter number of decimals to use for prices * * @since unknown * * @param int $number Number of decimals * @param int|string $amount Price */ $decimals = apply_filters( 'edd_sanitize_amount_decimals', 2, $amount ); $amount = number_format( (double) $amount, $decimals, '.', '' ); if( $is_negative ) { $amount *= -1; } /** * Filter the sanitized price before returning * * @since unknown * * @param string $amount Price */ return apply_filters( 'edd_sanitize_amount', $amount ); }