Hacker News new | ask | show | jobs
by dx034 1467 days ago
Such a shame that decimals don't get more attention. I program in Go a lot and they don't even have a fixed point number type built into the language. Floating point numbers always seems to be the default. And while there is support via third party packages, it makes everything harder to use, from communicating with databases to (de-)serializing data.

However, in reality most numbers I deal with can reasonably be assumed to have a maximum number of decimals and can be stored easily this way. I know way fewer examples where I'd need floating point precision than where I need a fixed number of decimals. But with poorer support I always fall back to using float.

1 comments

In what context couldn't you just use an integer?
You can multiply and use integers but it's a bit ugly. Especially if you work across systems, you'll always need to store notations on the multiplier used. Having a decimal as a built in type with that information stored would be much easier.

But in the end I tend to use that for most numbers, especially as compression in time series also often better works on integers than floats if you have gradual changes in the numbers.

Multiplication context maybe?