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; Link to comment https://forums.phpfreaks.com/topic/281638-money-formatting/ 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); Link to comment https://forums.phpfreaks.com/topic/281638-money-formatting/#findComment-1447156 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 Link to comment https://forums.phpfreaks.com/topic/281638-money-formatting/#findComment-1447157 Share on other sites More sharing options...
darkfreaks Posted August 28, 2013 Share Posted August 28, 2013 money_format may be a better solution. Link to comment https://forums.phpfreaks.com/topic/281638-money-formatting/#findComment-1447160 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, '.', ','); Link to comment https://forums.phpfreaks.com/topic/281638-money-formatting/#findComment-1447185 Share on other sites More sharing options...
AbraCadaver Posted August 28, 2013 Share Posted August 28, 2013 It's probably a string. $Price = number_format((float)$preownedinfo->Price, 2); Link to comment https://forums.phpfreaks.com/topic/281638-money-formatting/#findComment-1447197 Share on other sites More sharing options...
kawaii1001 Posted August 28, 2013 Author Share Posted August 28, 2013 Brilliant. Thank you! Link to comment https://forums.phpfreaks.com/topic/281638-money-formatting/#findComment-1447199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.