marcmira Posted February 14, 2017 Share Posted February 14, 2017 Hi everyone, I have this php code in which I can apply a number format feature when echoing $ask: <!DOCTYPE html> <html> <body> <?php $json_string = file_get_contents("https://api.flowbtc.com:8400/GetTicker/BTCBRL/"); $parsed_json = json_decode($json_string); $ask = $parsed_json->{'ask'}; echo number_format($ask, 2, ',', ''); ?> </body> </html> However, when I do it within an array so it works with my Messenger chatbot, it simply doesnt work. In the example below how can I do the number formating in the result of .$ask * 1.025 on the "value" line? <? header('Content-Type: application/json'); ////Text / Image / Structured /// $_POST['message']; /// Message user Inputs /// $_POST['senderid']; /// Facebook Sender ID /// $json_string = file_get_contents("https://api.flowbtc.com:8400/GetTicker/BTCBRL/"); $parsed_json = json_decode($json_string); $ask = $parsed_json->{'ask'}; $received_message = $_POST['message']; $message = array(); ///Text Message $message['bmsg'][0] = array( 'type'=>'text', 'value'=>'Valor de referencia de 1 bitcoin incluindo taxas: R$ ' .$ask * 1.025 ); echo json_encode($message); ?> Any help will be appreciated. Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/303194-number-formating-and-calculating-within-array/ Share on other sites More sharing options...
Barand Posted February 14, 2017 Share Posted February 14, 2017 'value'=>'Valor de referencia de 1 bitcoin incluindo taxas: R$ ' . number_format($ask * 1.025, 2); Quote Link to comment https://forums.phpfreaks.com/topic/303194-number-formating-and-calculating-within-array/#findComment-1542753 Share on other sites More sharing options...
marcmira Posted February 15, 2017 Author Share Posted February 15, 2017 Thanks Sen but either my chatbot doesnt accept this syntax or it is not working for another reason. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/303194-number-formating-and-calculating-within-array/#findComment-1542757 Share on other sites More sharing options...
Jacques1 Posted February 15, 2017 Share Posted February 15, 2017 If you've literally copied and pasted his code, you need to get rid of the semicolon. C'mon, this problem should be solvable with a bit of common sense. Quote Link to comment https://forums.phpfreaks.com/topic/303194-number-formating-and-calculating-within-array/#findComment-1542758 Share on other sites More sharing options...
marcmira Posted February 15, 2017 Author Share Posted February 15, 2017 I managed to do this by creating another variable before the array using the number format funciton and then replacing .ask with this new variable in the array. Quote Link to comment https://forums.phpfreaks.com/topic/303194-number-formating-and-calculating-within-array/#findComment-1542759 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.