j.g. Posted August 22, 2007 Share Posted August 22, 2007 Hello All! I'm working on something that isn't quite working right yet and am hoping someone out there can help me with it. Currently, if the user enters a list_price value of 25,000, my program is changing it to 25; if I enter 25000 (w/o the comma), it's displaying OK, but I'd like to be able to put the comma in the field. What do I need to change/add to accomplish this? Here's my code for it: <tr> <th>List Price</th> <td> <input type=text name='list_price' size=9 value='<?=htmlentities($property->getListPrice(), ENT_QUOTES)?>'> </td> </tr> and my 'getListPrice' function: function getListPrice() { return($this->data["list_price"]); } If I need to supply any additional info, please let me know. Thanks in advance for your time and expertise!! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66221-newbie-number-format-questin/ Share on other sites More sharing options...
tarun Posted August 22, 2007 Share Posted August 22, 2007 I Think: Number_Format Function Quote Link to comment https://forums.phpfreaks.com/topic/66221-newbie-number-format-questin/#findComment-331222 Share on other sites More sharing options...
j.g. Posted August 22, 2007 Author Share Posted August 22, 2007 Well, I'm a little bit closer I think; I changed my getListPrice function to: function getListPrice() { //return($this->data["list_price"]); return number_format($this->data["list_price"], 0, "", ","); } and, it's putting the comma in there if the user enters 80000 (output is 80,000) --- However, if the user puts a comma into this field ex: 80,000, it's still returning 80. Any ideas? I'd like them to be able to input the comma... Thanks much! -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66221-newbie-number-format-questin/#findComment-331234 Share on other sites More sharing options...
Barand Posted August 22, 2007 Share Posted August 22, 2007 The numeric value of 80,000 is 80, since the comma is treated as a non-numeric character. Don't put commas in until you have done all the calculations. Wait until you output the final result. Quote Link to comment https://forums.phpfreaks.com/topic/66221-newbie-number-format-questin/#findComment-331237 Share on other sites More sharing options...
j.g. Posted August 22, 2007 Author Share Posted August 22, 2007 Well, this function is still returning $80.00, even though 80,000 is in the db -- I'm assuming it has to do w/ the non-numeric comma, as just pointed out... What do I need to change to get the $80,000.00 output instead of $80.00? function format_money($dec, $prefix='$') { return("$prefix".sprintf("%01.2f",round($dec, 2))); } Any ideas? -j.g. Quote Link to comment https://forums.phpfreaks.com/topic/66221-newbie-number-format-questin/#findComment-331271 Share on other sites More sharing options...
Barand Posted August 22, 2007 Share Posted August 22, 2007 You should have 80000 in the db, not 80,000 Quote Link to comment https://forums.phpfreaks.com/topic/66221-newbie-number-format-questin/#findComment-331274 Share on other sites More sharing options...
j.g. Posted August 22, 2007 Author Share Posted August 22, 2007 But, if the user enters '80,000', that's what I'm storing. And, I also noticed that if I enter a # w/ both a comma and period, it's really messed up -- enter: 1,888.88 --> outputs $1.00 vs. $1,888.88 ??? Quote Link to comment https://forums.phpfreaks.com/topic/66221-newbie-number-format-questin/#findComment-331279 Share on other sites More sharing options...
Barand Posted August 22, 2007 Share Posted August 22, 2007 Periods are OK, it's the comma thats the problem. And are you storing these values in varchar fields (instead of numeric types, such as float, decimal or int) to accomodate the commas? Quote Link to comment https://forums.phpfreaks.com/topic/66221-newbie-number-format-questin/#findComment-331294 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.