Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F961909
PhortuneUtil.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
979 B
Referenced Files
None
Subscribers
None
PhortuneUtil.php
View Options
<?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
Details
Attached
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)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment