PHP Number Format

I have the following PHP Mathematical equation:
	$bv = 16150;
	$div = 100;
	$br = 6.30;

    $rate = $bv/$div;
	$sub_price = $br * $rate;
	$html = number_format($sub_price, 2, '.', ',');

	echo $html .'<br />';
	if ($html > 100) {
	echo $html;

Open in new window

The $html in this case is 1,017.45
The if $html > 100 will not work.
If I adjust the $bv so that the $html figure is less than 1000 it does work.  What am I doing wrong?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
You should be checking whether $sub_price is greater than 100:

if ($sub_price > 100) {
    echo $html;

Open in new window

$html is a string - $sub_price is the actual number.
Chris StanyonWebDevCommented:
The reason your code is not working when $html is above a thousand, is because the $html string then contains a comma, which prevents PHP from automatically casting the string to a number. If $html is less that 1000, it doesn't contain the comma and everything works.

An alternative to checking against $sub_price is to strip out the comma before checking if it's greater than 100, so that PHP can cast it to a number:

if (str_replace(",", "", $html) > 100) {
	echo $html;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.