faqts : Computers : Programming : Languages : PHP : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 20 people (50%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How do I take a variable, mutiply it by a constant and have the output include a dollar sign with two decimal places (currency) with proper rounding.

Sep 19th, 2005 15:40
Philippe Lhoste, Marcus Soares, George Federuik,


PHP4 and above:
$output = '$' . round($var * CONSTANT, 2);
PHP3:
$output = '$' . round((($var * CONSTANT) * 100 + 0.5) / 100);