Hacker News new | ask | show | jobs
by nly 2034 days ago
I was working on a problem yesterday at work where a remote system was sending prices (market data) to us in IEE754 binary doubles

One of the test vectors was 5.80, but when we were printing them out to 15 digits of precision (the maximum a double is guaranteed to preserve) we were seeing "5.80000019073486", where of course we expected to see "5.8".

As it turns out this is the closest to 5.8 you can get in single precision so the remote system was obviously sourcing these from a C 'float'.

sigh

2 comments

Everyone says that 'banks never use floating point to represent money'... but when you talk to people actually working in banks and other financial institutions and actually look at their code turns out they're using floating point all over the place.
I can tell you for a fact that at least one large data vendor uses floating point almost exclusively internally :-)

The thing is, it's actually 'fine' until you actually need to do a calculation. Once you get there you need to convert to decimal and round to however many dp's you should be using.

Holy cow. Which market data provider in their sane mind would send decimals as floats? I don't think I've ever encountered binary market data using anything but fixed-point decimals (so essentially, integers) for representing prices.
Trading platforms using older tech (pretty much anyone not owned by the big groups) do this all the time.