Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Helper for quick price formatting
- *
- * @param float $price
- * @param bool|string $pattern
- * @return string
- * <code>
- * format_price(45689.95); // 45 689.95
- * format_price(45689.0); // 45 689
- * format_price(45689.95, '%price% руб.'); // 45 689.95 руб.
- * </code>
- */
- function format_price($price, $pattern = false)
- {
- $price = number_format($price, 2, '.', ' ');
- if (substr($price, -3) === '.00') {
- $price = substr($price, 0, -3);
- }
- if ($pattern) {
- $price = str_replace('%price%', $price, $pattern);
- }
- return $price;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement