kawaii1001 Posted August 28, 2013 Share Posted August 28, 2013 Could you please tell me how to make $Price below format as a money value. <?php $preowned = simplexml_load_file('file.xml'); foreach ($preowned as $preownedinfo): $ADID=$preownedinfo->ADID; $CompanyID=$preownedinfo->CompanyID; $Category=$preownedinfo->Category; $StockNumber=$preownedinfo->StockNumber; $Year=$preownedinfo->Yrs; $Make=$preownedinfo->Make; $Model=$preownedinfo->Model; $Trim=$preownedinfo->Trim; $Odometer=$preownedinfo->ExtraField->ContentEN->Odometer; $ExteriorColor=$preownedinfo->ExtraField->ContentEN->ExteriorColor; $InteriorColor=$preownedinfo->ExtraField->ContentEN->InteriorColor; $Engine=$preownedinfo->ExtraField->ContentEN->Engine; $Transmission=$preownedinfo->ExtraField->ContentEN->Transmission; $Price=$preownedinfo->Price; $Options=$preownedinfo->ExtraField->ContentEN->Options; $AdDescription=$preownedinfo->AdDescription; $MainPhoto=$preownedinfo->MainPhoto; $AdditionalPhoto=$preownedinfo->AdditionalPhoto; $Doors=$preownedinfo->ExtraField->ContentEN->Doors; Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted August 28, 2013 Share Posted August 28, 2013 just use number_format() : $price = number_format($preownedinfo->Price, 2); Quote Link to comment Share on other sites More sharing options...
kawaii1001 Posted August 28, 2013 Author Share Posted August 28, 2013 I'm getting this message when I've tried that: Warning: number_format() expects parameter 1 to be double Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 28, 2013 Share Posted August 28, 2013 money_format may be a better solution. Quote Link to comment Share on other sites More sharing options...
kawaii1001 Posted August 28, 2013 Author Share Posted August 28, 2013 Hmmmm. Still getting the same message. I have it set like this: <?php $preowned = simplexml_load_file('file.xml'); foreach ($preowned as $preownedinfo): $ADID=$preownedinfo->ADID; $CompanyID=$preownedinfo->CompanyID; $Category=$preownedinfo->Category; $StockNumber=$preownedinfo->StockNumber; $Year=$preownedinfo->Yrs; $Make=$preownedinfo->Make; $Model=$preownedinfo->Model; $Trim=$preownedinfo->Trim; $Odometer=$preownedinfo->ExtraField->ContentEN->Odometer; $ExteriorColor=$preownedinfo->ExtraField->ContentEN->ExteriorColor; $InteriorColor=$preownedinfo->ExtraField->ContentEN->InteriorColor; $Engine=$preownedinfo->ExtraField->ContentEN->Engine; $Transmission=$preownedinfo->ExtraField->ContentEN->Transmission; $Price=$preownedinfo->Price; $Options=$preownedinfo->ExtraField->ContentEN->Options; $AdDescription=$preownedinfo->AdDescription; $MainPhoto=$preownedinfo->MainPhoto; $AdditionalPhoto=$preownedinfo->AdditionalPhoto; $Doors=$preownedinfo->ExtraField->ContentEN->Doors; $price = '$' . money_format($Price, 2, '.', ','); Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 28, 2013 Share Posted August 28, 2013 (edited) It's probably a string. $Price = number_format((float)$preownedinfo->Price, 2); Edited August 28, 2013 by AbraCadaver Quote Link to comment Share on other sites More sharing options...
kawaii1001 Posted August 28, 2013 Author Share Posted August 28, 2013 Brilliant. Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.