0

I know i could write a custom function that does just this, but it feels like this is such a function that should already exist (built in).

So, i simply just want to add spaces to make it easier to read:

1200 would become: 1 200 10000 would become: 10 000 150000 would become: 150 000 etc...

Is there a function to just "pop" in a string/character into another string at a specified position?

1 Answer 1

4

Are you just formatting numbers? there's number_format() which will accept any type of seperator:

$formatted = number_format(1200, 0, '.', ' '); // "1 200"
                                 1   2    3
1. # of decimal places
2. decimal place character (not inserted, since we've specified 0 decimals)
3. thousands separator (space, in this case)
Sign up to request clarification or add additional context in comments.

1 Comment

That's perfect, even better than the function i was looking for. Thanks, man!

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.