Answered
PHP/MySQL Decimal Numbers
Hi,
I'm working on a real estate site. Most of the monthly apartment rental rates are round numbers like $950, however a few have odd prices like $1070.76 (hence the need for decimal data types in MySQL).
On the page where all the apartment listings are, what I want to do is remove the decimal point and zeros if the number is round because all the zeros are distracting (and unnecessary). For example:
I have this snippet of code:
if ($r->maxRent == 0) {
$price = 'Asking rent $';
$price .= $r->minRent;
$price .= ' per month';
} else {
$price = 'Asking rent $';
$price .= $r->minRent;
$price .= '-';
$price .= $r->maxRent;
$price .= ' per month';
}
Which displays this:
Asking rent $810.00 - 950.00 per month
Asking rent $1070.76 - 1200.00 per month
Asking rent $1335.00 per month
But I want things to display like this:
Asking rent $810 - 950 per month
Asking rent $1070.76 - 1200 per month
Asking rent $1335 per month
Do I need to do this with regular expressions (voodoo!) or is there another way? I'm currently in a situation where I have to use rather outdated versions of everything (PHP 4.1.2 / MySQL 3.23) if that makes a difference in this case.
I've looked through my books and tried googling & searching the forums for an answer, but I'm unsure of exactly what it is I should be looking for, so I'm not having any luck. Any assistance would be greatly appreicated.
Regards,
Bev
I'm working on a real estate site. Most of the monthly apartment rental rates are round numbers like $950, however a few have odd prices like $1070.76 (hence the need for decimal data types in MySQL).
On the page where all the apartment listings are, what I want to do is remove the decimal point and zeros if the number is round because all the zeros are distracting (and unnecessary). For example:
I have this snippet of code:
if ($r->maxRent == 0) {
$price = 'Asking rent $';
$price .= $r->minRent;
$price .= ' per month';
} else {
$price = 'Asking rent $';
$price .= $r->minRent;
$price .= '-';
$price .= $r->maxRent;
$price .= ' per month';
}
Which displays this:
Asking rent $810.00 - 950.00 per month
Asking rent $1070.76 - 1200.00 per month
Asking rent $1335.00 per month
But I want things to display like this:
Asking rent $810 - 950 per month
Asking rent $1070.76 - 1200 per month
Asking rent $1335 per month
Do I need to do this with regular expressions (voodoo!) or is there another way? I'm currently in a situation where I have to use rather outdated versions of everything (PHP 4.1.2 / MySQL 3.23) if that makes a difference in this case.
I've looked through my books and tried googling & searching the forums for an answer, but I'm unsure of exactly what it is I should be looking for, so I'm not having any luck. Any assistance would be greatly appreicated.
Regards,
Bev