# PHP Number Format

I have the following PHP Mathematical equation:
``````
<?php
\$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;
}
?>
``````

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?
LVL 8
###### Who is Participating?

x
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.

WebDevCommented:
You should be checking whether \$sub_price is greater than 100:

``````if (\$sub_price > 100) {
echo \$html;
}
``````

\$html is a string - \$sub_price is the actual number.
0
WebDevCommented:
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;
}
``````
0

Experts Exchange Solution brought to you by