Page 1 of 1

number with % (percent) sign change to number

Posted: Sun Nov 30, 2008 10:06 am
by myplaces
I have two forms, where user must enter number
First form - number (for example - 100)
Second form - percent. User must enter number without percent sign (for example- 10)

Then i do calculations.
First number multiply by percent (100*10/100)
But if user will enter not 10, but 10% , then calculation will be 100*10%/100

So i need to convert possible 10% to 10

may be it is simple solution, but my programming knowledge is very poor.....

hmmm, it seem it automaticaly is number? If I enter number with % sign, in calculation is used only number without percent sign?
Is it true?

Re: number with % (percent) sign change to number

Posted: Sun Nov 30, 2008 10:16 am
by Eran
PHP will automatically convert string into number when used with math operators. You can make sure by casting it into an integer -

Code: Select all

$number = (int) $number;

Re: number with % (percent) sign change to number

Posted: Sun Nov 30, 2008 10:25 am
by myplaces
Thanks a lot.