Jump to content


Photo

Thousand separator


  • Please log in to reply
8 replies to this topic

#1 AndieB

AndieB
  • Members
  • PipPipPip
  • Advanced Member
  • 77 posts
  • LocationSweden
  • Age:37

Posted 13 April 2006 - 06:39 PM

Hi all!


If I have a variable, lets call it $number, and it contains the number 21500.
Is there a function which can performe a thousand separator function, so the displayed result will
be 21 500?

And even at next level, million separator?

Thankful for anykind of help!

--Andreas

" Start by looking in the mirror before pointing the finger outwards... "
" Nothing can be, until it has passed your mind... "

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 13 April 2006 - 06:47 PM

[a href=\"http://ca3.php.net/manual/en/function.number-format.php\" target=\"_blank\"]number format function[/a]
Legend has it that reading the manual never killed anyone.
My site

#3 deadonarrival

deadonarrival
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts

Posted 13 April 2006 - 08:45 PM

Simple usage.

$number = "1337357";
$number = number_format($number);
echo $number;

DO {
$this->time_warp("Jump to the left","Step to the right","Bend knees in time");
} WHILE (2>1)

Warning: The above post may not make a lot of sense, and the sentence structure will suck. I tend to ramble a lot. Sorry ;-)

#4 lansing

lansing
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationClinton, TN USA

Posted 13 April 2006 - 10:02 PM

Can this be used on the decimal(6,2) data type?

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 13 April 2006 - 10:52 PM

$n = 12345.67;

echo number_format ($n, 2);

--> 12,345.67
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 lansing

lansing
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationClinton, TN USA

Posted 14 April 2006 - 04:50 PM

[!--quoteo(post=364618:date=Apr 13 2006, 05:52 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 13 2006, 05:52 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$n = 12345.67;

echo number_format ($n, 2);

--> 12,345.67
[/quote]Thanks...

#7 AndieB

AndieB
  • Members
  • PipPipPip
  • Advanced Member
  • 77 posts
  • LocationSweden
  • Age:37

Posted 16 April 2006 - 07:34 AM

Follow-Up question:


In Sweden we tend to use the , (comma) as a separator for decimals. I've noticed that PHP will not accept me doing a calculation using the comman (,) sign. (ie 30000 * 1,25), I must do this (30000 * 1.25).

Is this something one can change or do I have to live with it?


Thanks 4 any kind of help!

--Andreas
" Start by looking in the mirror before pointing the finger outwards... "
" Nothing can be, until it has passed your mind... "

#8 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 16 April 2006 - 08:39 AM

[!--quoteo(post=365241:date=Apr 16 2006, 08:34 AM:name=AndieB)--][div class=\'quotetop\']QUOTE(AndieB @ Apr 16 2006, 08:34 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Follow-Up question:
In Sweden we tend to use the , (comma) as a separator for decimals. I've noticed that PHP will not accept me doing a calculation using the comman (,) sign. (ie 30000 * 1,25), I must do this (30000 * 1.25).

Is this something one can change or do I have to live with it?
Thanks 4 any kind of help!

--Andreas
[/quote]

as far as i know, you have to live with it, just like all us non-americans have to get used to spelling the word 'colour' without the 'u' :)
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 16 April 2006 - 09:10 AM

Have a look at [a href=\"http://www.php.net/setlocale\" target=\"_blank\"]http://www.php.net/setlocale[/a]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users