Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do a round a figure to the nearest 2 decimal places?

Status
Not open for further replies.

tippytarka

Programmer
Joined
Jul 19, 2004
Messages
115
Location
GB
i'm trying to round a figure to two decimal places. the result i get is '2234.6789' and i want the result to look like this...... '2234.68'

here's my code that calculates my total cost and prints to the browser


// CALCULATE total cost
function total_cost($total_base,$total_addtional_selects,$total_vat) {
 $price = $total_base + $total_addtional_selects + $total_vat;
 return $price;
}

$total_base = purchase_selected_job_titles($licence,$count);
$total_addtional_selects = $tel_value + $email_value;
$total_vat = vat($vat_base,$vat_tel_email);
$final_total_cost = total_cost($total_base,$total_addtional_selects,$total_vat);
print "$final_total_cost";


cheers!
 
$final_total_cost = round(total_cost($total_base,$total_addtional_selects,$total_vat), 2);

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
thank you guys ..i realise that was a bit of an easy one. next time i read up before asking.
 
Not spelled out - but if you read the PHP manual entry for number_format it appears that it rounds the number automatically to the desired number of decimal places:
Code:
<?php
$number = 1234.5678;
// english notation without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top