On the way to find out RSS

Posting stuff that's too big for twitter, too arty for flickr and too non-technical for my blog

Archive

May
7th
Thu
permalink

Dealing with currency in Javascript

I probably don’t need to tell you that it’s a very bad idea to do any floating point arithmetic in Javascript. There’s no arbitrary precision decimal library (like BigDecimal). If you have attempted it, you know that this ends very, very badly.

So what’s a dev to do when you need to do some simple arithmetic (adding, subtracting etc) on the client-side?

The answer is to represent your currency amounts as an integral number of cents and use integer arithmetic. Here’s a couple of utility functions that might help:

A word of warning: you could call formatAsCurrency() on a floating point number, but this won’t give you the results you want. So make sure you only call it on Integers only. There’s still limitations on very large integers, but for most purposes this should work just fine.

Apr
2nd
Thu
permalink
Are you 1337 enough?

Are you 1337 enough?

Feb
26th
Thu
permalink
Feb
15th
Sun
permalink
[Flash 9 is required to listen to audio.]

Just found an old ‘Cafe del Mar’ style track I wrote years ago with Reason. Enjoy!

Feb
13th
Fri
permalink
Feb
12th
Thu
permalink
A buddha head my sister bought me from Cambodia against a painting I bought in a market in Beijing.

A buddha head my sister bought me from Cambodia against a painting I bought in a market in Beijing.

permalink
The Tokoloshe I bought in Malawi.  According to the locals of southern Africa this little guy brings good luck to your home.

The Tokoloshe I bought in Malawi.  According to the locals of southern Africa this little guy brings good luck to your home.

permalink

iPrimus jumping up and down to be part of the filtering trial?

Apparently our corporate internet provider iPrimus is “jumping up and down” to be part of the filtering trial. Who in their right mind will use them if they really do have that attitude?

Senator Stephen Conroy, what the fuck are you thinking anyway?

permalink
Every once in a while I get that ‘stabby feeling’
Feb
3rd
Tue
permalink

Welcome to my tumblr. Stay tuned as I’m sure to intrigue, entertain and quite possibly horrify you.