Is there a C++ equivalent to Java's BigDecimal?

Solution 1:

There exists a huge library called GMP (GNU multiple precision library) which supports this and also has C++ bindings, though to be honest the C++ interface is a bit wonky and outdated.

An example from the documentation, the following creates a float called f with at least 500 bits of precision:

mpf_class f(1.5, 500);

Solution 2:

Take your pick. There are a bunch of them out there. For instance, you can consult the list on Wikipedia.

Solution 3:

The question is a bit old, but for other people that have the same need : Boost.multiprecision is probably what you're looking for.

http://www.boost.org/doc/libs/1_57_0/libs/multiprecision/doc/html/boost_multiprecision/tut/floats/cpp_dec_float.html

It's an arbitrary precision library that can handle 10-based decimals.