Page MenuHomePhorge

PhortuneUtil.php
No OneTemporary

Size
979 B
Referenced Files
None
Subscribers
None

PhortuneUtil.php

<?php
final class PhortuneUtil {
public static function parseCurrency($string) {
$string = trim($string);
if (!preg_match('/^[-]?[$]?\d+([.]\d{0,2})?$/', $string)) {
throw new Exception("Invalid currency format ('{$string}').");
}
$value = str_replace('$', '', $string);
$value = (float)$value;
$value = (int)round(100 * $value);
return $value;
}
public static function formatCurrency($price_in_cents) {
if (!preg_match('/^[-]?\d+$/', $price_in_cents)) {
throw new Exception("Invalid price in cents ('{$price_in_cents}').");
}
$negative = ($price_in_cents < 0);
$price_in_cents = abs($price_in_cents);
$display_value = sprintf('$%.02f', $price_in_cents / 100);
if ($negative) {
$display_value = '-'.$display_value;
}
return $display_value;
}
public static function formatBareCurrency($price_in_cents) {
return str_replace('$', '', self::formatCurrency($price_in_cents));
}
}

File Metadata

Mime Type
text/x-php
Expires
Tue, Jun 17, 11:50 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
230303
Default Alt Text
PhortuneUtil.php (979 B)

Event Timeline