April 21, 200917 yr Hi folks, In a little bit of a pickle and need some assistance. I've been working on a site for an estate agent, i have made it completely from scratch, which i'm pretty chuffed about as i've never taken on a project of such scale. However, there is a very small problem that is driving me insane, I have a Decimal field in my database to hold the price of each house. When for example i enter 10,000 only 10 is entered into the field. So i just wrote 10000 to overcome this....how now, do i get it to output as 10,000? I hope that made sense, some help would be much appreciated, its frustrating that such a small thing is causing such a big problem!!! Thanks in advance.
April 21, 200917 yr http://www.php.net/manual/en/function.number-format.php Store without commas in the database and avoid using commas in data entry, then just use this function when you need to output the value on-screen.
April 21, 200917 yr Author Thanks, i was just looking at that actually. I tried: $number = ".$row[10]."; $english_format_number = number_format($number); echo " £ ".$english_format_number." "; This i would have expected to output £23,000 as 23000 is the value in the database, however, it output £0.23 Any ideas what i need to change? Thanks again.
April 21, 200917 yr In the DECIMAL field in the DB you want the 'Length/Values' set to '10,2' Try that
April 21, 200917 yr Author Thanks very much folks. The solution was pretty much a combination of each. $number = $row[10]; $pr = number_format($number); echo " £ ".$pr." "; (and i also set row 10 , Decimal to 10,2) Thanks again! :-D
Create an account or sign in to comment