• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / edd_format_amount() – Returns a nicely formatted amount.

You appear to be a bot. Output may be restricted

Description

Returns a nicely formatted amount.

Usage

$string = edd_format_amount( $amount, $decimals );

Parameters

$amount
( string ) required – Price amount to format
$decimals
( string ) optional default: 1 – Whether or not to use decimals. Useful when set to false for non-currency numbers.

Returns

string $amount Newly formatted amount or Price Not Available

Source

File name: easy-digital-downloads/includes/formatting.php
Lines:

1 to 30 of 30
function edd_format_amount( $amount, $decimals = true ) {
  $thousands_sep = edd_get_option( 'thousands_separator', ',' );
  $decimal_sep   = edd_get_option( 'decimal_separator', '.' );

  // Format the amount
  if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
    $whole = substr( $amount, 0, $sep_found );
    $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
    $amount = $whole . '.' . $part;
  }

  // Strip , from the amount (if set as the thousands separator)
  if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
    $amount = str_replace( ',', '', $amount );
  }

  // Strip ' ' from the amount (if set as the thousands separator)
  if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
    $amount = str_replace( ' ', '', $amount );
  }

  if ( empty( $amount ) ) {
    $amount = 0;
  }

  $decimals  = apply_filters( 'edd_format_amount_decimals', $decimals ? 2 : 0, $amount );
  $formatted = number_format( $amount, $decimals, $decimal_sep, $thousands_sep );

  return apply_filters( 'edd_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep );
}
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 26th November 2019

Primary Sidebar

Information

Function name: edd_format_amount
Plugin ref: Easy Digital Downloads
Version: 2.10.1
Sourcefile: includes/formatting.php
File ref: includes/formatting.php
Deprecated?: No
API Letters: A,E,F

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.7
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites