Removing Decimal Point

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JimmyNo
Forum Newbie
Posts: 3
Joined: Wed Oct 22, 2008 10:41 am

Removing Decimal Point

Post by JimmyNo »

Hi

I am new to PHP and I have a form where the person has to manually enter the price for a item. For some reason my payment processor wont accept decimal points!! Example if a item is 1200 or 1200.00 and that is submitted then it appears as 12.00 at the processors end. To have the value 1200.00 appear on my payment processor someone would have to type 120000!

Also if someone types in 1200 is there a way I can have two extra 0's added?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Removing Decimal Point

Post by papa »

JimmyNo
Forum Newbie
Posts: 3
Joined: Wed Oct 22, 2008 10:41 am

Re: Removing Decimal Point

Post by JimmyNo »

Unfortunately thats no good as I need to remove the decimal point.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Removing Decimal Point

Post by onion2k »

JimmyNo wrote:Also if someone types in 1200 is there a way I can have two extra 0's added?
Multiply the number by 100?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Removing Decimal Point

Post by VladSun »

Maybe if we had a look at your "payment processor" coude we would be more helpful ;)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Removing Decimal Point

Post by aceconcepts »

Code: Select all

number_format()
JimmyNo
Forum Newbie
Posts: 3
Joined: Wed Oct 22, 2008 10:41 am

Re: Removing Decimal Point

Post by JimmyNo »

Code: Select all

$new_string = preg_replace("/[^a-zA-Z0-9s]/", "", $string);
FYI: The above removed the decimal point!
Multiply the number by 100?
Er...... Bloody hell yes! That would sort out my problem including the decimal point! Cheers Mate! I couldn't see the forest through the trees! The simple solutions wins the prize!
Post Reply