How to get formatted total amount programmatically? I want to get the formatted total amount of my cart items.

I used the following code

$order = commerce_cart_order_load($user-&gt;uid);
$wrapper = entity_metadata_wrapper('commerce_order', $order);
$line_items = $wrapper-&gt;commerce_line_items;
$total = commerce_line_items_total($line_items);


It returns me $4000 instead of $40.00.

On shoping cart page it display $40.00. How can I get the price in this format?

I want this in commerce way not some custom php like number_format etc.
I had the same issue. I solved this issue by dividing the total by 100. You can see the total amount in the field_revision_commerce_total table. After dividing, I used commerce_currency_format($amount,NULL,NULL) to get the currency format.