• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cart Class Price Format

#1
[eluser]Unknown[/eluser]
Hello, I have a question, I've been using the Cart class and it works great however I was wondering what can I do, so for even numbers when the total is calculated, it doesn't take the two zeros for the decimal points off

So if I have
$data = array(
array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.00,
'name' => 'T-Shirt'
),
array(
'id' => 'sku_567ZYX',
'qty' => 1,
'price' => 9.00,
'name' => 'Coffee Mug'
)
);

$this->cart->total();
Shows 48.00 instead of 48


Thanks

#2
[eluser]Matalina[/eluser]
Code:
number_format($this->cart->total(),2)

should work

#3
[eluser]CroNiX[/eluser]
I thought they were trying to remove the decimal, not add it.
if cart->total() was 1234.56:
Code:
$total = (int)$this->cart->total();  //cast as int.   becomes 1234
$total = number_format($this->cart_total); //produces 1,234 with no decimal, but adds thousands separator

#4
[eluser]Unknown[/eluser]
@Matalina, Thanks for your help.
@CroNix I don't think they would remove it since some merchants API's require the no cents decimals in the items price.

#5
[eluser]CroNiX[/eluser]
Quote:Shows 48.00 instead of 48
I thought you wanted it to show 48 with no decimal.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.