0

Hi guys and thank you so much for your support on the few weeks

i need to convert

{$data['rank']['points']}

to english notation (default) to shown as 1,235 rather than 1235

the data originates from an JSON file so data is being pulled every hour the above variable is what is required to output the number

1

1 Answer 1

2

See https://www.php.net/number_format

echo number_format($data['rank']['points']);

Example: http://3v4l.org/ih3lT

Edit: From your full code, I can see you're looking to embed this in a string.

So change this:

echo "    <td><strong>Military Points:</strong> {$data['rank']['points']}</td>\n"; 

To this:

echo "    <td><strong>Military Points:</strong> " . number_format($data['rank']['points'])  . "</td>\n"; 
Sign up to request clarification or add additional context in comments.

11 Comments

Does the locale need to be set as well?
I believe you might get a decimal point or something else besides a comma if you do not set the proper settings.
No locale is needed if you just want the default behavior: "If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands." You can pass in additional args if you need to change the decimal point or thousands separator, but that's optional.
It defaults to US formatting, it appears. You'd need to use us1.php.net/manual/en/function.localeconv.php settings manually for other locales, but that's beyond this scope. My mistake
this data is not shown with a database its JSON file which i $json = $json = file_get_contents($url); - {$data['rank']['points']} is the output needed to show the number data, i have tried the above and all it doe it repeat the content and bracket it as number_format(28282990) so it didnt work
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.