Tag Archives: money

Money, Money, Money My Life 09 MAR 2011

So you all saw yesterday’s post regarding our financial situation. The funny thing is, most of my posts for this site are written well in advance (you would be interested to know that there is already a post scheduled for each and every day for the rest of March), and the situation yesterday’s post addressed, was actually resolved last Friday when our prayers were answered in quite a surprise fashion.

UIF caught us completely by surprise and paid out early, far, far earlier than what we had expected and with a far, far greater amount than what we could have hoped for.

This now more than covers the shortfall until Chantelle returns to work and receives her first paycheck at the end of April, taking a huge burden off our shoulders in the process.

Of course, this exceptionally good news meant that for a change I could enjoy my weekend, translating into two walks along the beach, loads and loads of gardening, landscaping and household chores, a morning run, a visit to the Funakoshi karate fundraiser pet show (which we were kind of late getting to), two new websites configured and populated with content, a pencilled, inked, lettered and coloured webcomic, and of course an enjoyable supper with the in-laws over at our place on Saturday night.

Ah, much, much better when you are not stressing about money all the time! ;)

How to Store Decimal Currency Values in MySQL CodeUnit 17 JAN 2010

Now while storing integers and numerals in MySQL is pretty rock solid and easy to do, storing decimal values like currency, in other words money, isn’t quite as intuitive when you have a phpMyAdmin structure tab open in front of you.

When it comes to storing non integer numbers, you pretty much have the choice of taking either the FLOAT or DECIMAL route. Now FLOAT is intended for very large values and rounds as a floating point, which is a bit of a problem at times because floating point arithmetic is not entirely exact, particularly when it comes to rounding – which is definitely not a behaviour you want went it comes to adding and subtracting all those cents in any of your financial applications.

DECIMAL was introduced as an “exact packed decimal number”, but prior to MySQL 5.0, any calculations performed on a DECIMAL type column would be done using floating point arithmetic, which didn’t really solve the problem. However, starting with MySQL 5.0 and above, the server now uses a separate fixed-point arithmetic library for this, making it far more precise and far less prone to rounding errors.

Thus the best way to currently store your money value in whatever currency, be it in Rands or US Dollars is to declare a DECIMAL column type and assign it a length/value of 10,2 (where 2 indicates the length of the fractional part of the number).

(Of course you could always be a Smart Alec and simply save everything as cents in the first place)