Pages

Currency Format in PHP

here's an example you can use if you want to display the value of $price in currency format:

for example:

<?php
$price = 1.51;
$tax = .19
$total = $price + $tax; // $1.70

echo $total;
?>

the OUTPUT will look like this: 1.7

but if you want it to show in currency value its better like this:

1.60 like in cents and dollars, well its simple, just add the number_format() function. we change our code to this:

<?php
$price = 1.51;
$tax = .19
$total = $price + $tax; // $1.70

echo number_format($total, 2, '.', ',');
?>

the OUTPUT will look like this: 1.70

hope that helps explain what i was trying to do on my previous post

No comments:

Post a Comment