kawaii1001 Posted September 18, 2013 Share Posted September 18, 2013 I am getting the following error message with the below code: Warning: number_format() expects parameter 1 to be double, object given in ... <?php $price=$preownedinfo->Price; $formatted_price = number_format($price, 2); echo $formatted_price; ?> Can you tell me what might be the issue. Thanks. Link to comment https://forums.phpfreaks.com/topic/282255-help-with-number_format/ Share on other sites More sharing options...
AbraCadaver Posted September 18, 2013 Share Posted September 18, 2013 Edit: Just saw it was an object, I was thinking string: var_dump($price); Depends on what echo $price; shows, but most likely: $price = (float)$preownedinfo->Price; //or $formatted_price = number_format((float)$price Link to comment https://forums.phpfreaks.com/topic/282255-help-with-number_format/#findComment-1450099 Share on other sites More sharing options...
requinix Posted September 18, 2013 Share Posted September 18, 2013 If you're getting this from SimpleXML, pretty much everything it returns is an object. Use typecasting like Abra showed. Link to comment https://forums.phpfreaks.com/topic/282255-help-with-number_format/#findComment-1450100 Share on other sites More sharing options...
kawaii1001 Posted September 18, 2013 Author Share Posted September 18, 2013 Excellent. Worked. Thanks! Link to comment https://forums.phpfreaks.com/topic/282255-help-with-number_format/#findComment-1450130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.