PHP's number_format(); breaks my form. Oy!

13:43.17 - Tuesday 1st August 2006   (Link to This Entry)


Interesting PHP buglet of the month. I had a call from a client saying that the new prices he'd entered into his website's admin area were coming back as £1 and £2 instead of the thousands that they should have been. I asked a few questions but it suddenly occurred to me that if you entered a comma in a number value, that would screw things up.

The client, of course, insisted that they were not entering commas into anything, but it transpires that when you pull a value from the DB and run it through number_format() (to get the value to two decimal places and present it as a currency) it actually seperates the groups of three digits with a comma. So:returns "1,234.50" rather than the "1234.50" I was expecting.

This is all well and good until you actually save it in a form, whereby the comma ends up sending two seperate values for the same variable. Since only the first is used, the PHP on the receiving end sees '1' instead of '1234.50' and all hell breaks loose.

Well not really - the problem was spotted after only four items had gone wonky and before they actually had any customers, so nothing was lost on this little voyage of discovery. I wonder if our contract contains a clause absolving us of responsibility for stuff like this?

Dude goes to Scotland. Again.

20:14.06 - Tuesday 1st August 2006   (Link to This Entry)


Yes indeedy, it transpires that my mate K isn't going over to Amsterdam as previously planned, so for a laugh I said he could always go camping up in Scotland with me. He says yes, I say 'OK then!' and we're now off on a trip up to Glen Nevis (again!) at the end of the month - hurrah!

If the weather holds we'll have a go at getting up that mountain again, but I'm still a fat bastard so it may not happen. There's a Bank Holiday on the Monday so if I can take the Friday off we'll make a long weekend of it.


[ 2 comments pending ]