I'm trying to add subtract and multiply numbers with huge decimals C++.
Example:
4125487821547.87879845215584844588 - 354556689.899455132265468
What I figured so far is that I need to save inputs as a string, but not sure how to proceed after that.
Appreciate the help in advance Thanks
You need a big integer class or library. There are several implementations available, just to give you an overview on how to use such an external dependency, here is a solution based on Boost:
You can now construct instances by passing string or integral literals to the constructor and do all standard arithmetic operations with these objects, e.g.
One nice detail of such classes is that they usually demonstrate one of the few justified scenarios for non-explicit constructors with one argument, i.e., for the sake of smooth interoperability with builtin integral types. Example:
You only need the Boost headers for these snippets, no linkage is required. Check out the docs when proceeding with this library.