SHARE
TWEET

format_price

a guest Jun 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Helper for quick price formatting
  3.  *
  4.  * @param float $price
  5.  * @param bool|string $pattern
  6.  * @return string
  7.  * <code>
  8.  * format_price(45689.95); // 45 689.95
  9.  * format_price(45689.0); // 45 689
  10.  * format_price(45689.95, '%price% руб.'); // 45 689.95 руб.
  11.  * </code>
  12.  */
  13. function format_price($price, $pattern = false)
  14. {
  15.     $price = number_format($price, 2, '.', ' ');
  16.     if (substr($price, -3) === '.00') {
  17.         $price = substr($price, 0, -3);
  18.     }
  19.     if ($pattern) {
  20.         $price = str_replace('%price%', $price, $pattern);
  21.     }
  22.     return $price;
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top