public/wordpress/wp-content/plugins/wp-courseware/includes/functions/formatting.php
/**
 * Format Decimal Numbers.
 *
 * Sanitize, remove decimals, and optionally round + trim off zeros.
 *
 * This function does not remove thousands - this should be done before passing a value to the function.
 *
 * @since 4.3.0
 *
 * @param  float|string $number Expects either a float or a string with a decimal separator only (no thousands).
 * @param  mixed        $dp Number of decimal points to use, blank to use wpcw_get_currency_decimals, or false to avoid all rounding.
 * @param  bool         $trim_zeros From end of string.
 *
 * @return string
 */
Format Decimal Numbers.
Sanitize, remove decimals, and optionally round + trim off zeros.

This function does not remove thousands - this should be done before passing a value to the function.



@param  float|string $number Expects either a float or a string with a decimal separator only (no thousands).
@param  mixed        $dp Number of decimal points to use, blank to use wpcw_get_currency_decimals, or false to avoid all rounding.
@param  bool         $trim_zeros From end of string.

@return string
Format Decimal Numbers . Sanitize remove decimals and optionally round + trim off zeros . This function does not remove thousands - this should be done before passing a value to the function . @param float|string $number Expects either a float or a string with a decimal separator only ( no thousands ) . @param mixed $dp Number of decimal points to use blank to use wpcw_get_currency_decimals or false to avoid all rounding . @param bool $trim_zeros From end of string . @return string
function wpcw_format_decimal( $number, $dp = false, $trim_zeros = false ) {
	$locale   = localeconv();
	$decimals = array( wpcw_get_currency_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] );
	if ( ! is_float( $number ) ) {
		$number = str_replace( $decimals, '.', $number );
		$number = preg_replace( '/[^0-9\.,-]/', '', wpcw_clean( $number ) );
	}
	if ( false !== $dp ) {
		$dp     = intval( '' === $dp ? wpcw_get_currency_decimals() : $dp );
		$number = number_format( floatval( $number ), $dp, '.', '' );
	} elseif ( is_float( $number ) ) {
		$number = str_replace( $decimals, '.', sprintf( '%.' . wpcw_get_rounding_precision() . 'f', $number ) );
		$trim_zeros = true;
	}
	if ( $trim_zeros && strstr( $number, '.' ) ) {
		$number = rtrim( rtrim( $number, '0' ), '.' );
	}
	return $number;
}
function wpcw_format_decimal ( $ number , $ dp = false , $ trim_zeros = false ) { $ locale = localeconv ( ) ; $ decimals = array ( wpcw_get_currency_decimal_separator ( ) , $ locale [ 'decimal_point' ] , $ locale [ 'mon_decimal_point' ] ) ; if ( ! is_float ( $ number ) ) { $ number = str_replace ( $ decimals , '.' , $ number ) ; $ number = preg_replace ( '/[^0-9\.,-]/' , '' , wpcw_clean ( $ number ) ) ; } if ( false !== $ dp ) { $ dp = intval ( '' === $ dp ? wpcw_get_currency_decimals ( ) : $ dp ) ; $ number = number_format ( floatval ( $ number ) , $ dp , '.' , '' ) ; } elseif ( is_float ( $ number ) ) { $ number = str_replace ( $ decimals , '.' , sprintf ( '%.' . wpcw_get_rounding_precision ( ) . 'f' , $ number ) ) ; $ trim_zeros = true ; } if ( $ trim_zeros && strstr ( $ number , '.' ) ) { $ number = rtrim ( rtrim ( $ number , '0' ) , '.' ) ; } return $ number ; }
Format Decimal Numbers.
Format Decimal Numbers .
// Remove locale from string. // DP is false - don't use number format, just return a string using whatever is given. Remove scientific notation using sprintf. // We already had a float, so trailing zeros are not needed.