With float
there is nothing to do. Essentially I've already replied in this answer (there are several links to other information, I recommend reading all, especially those in English, if you can). This seems to be one of the most common problems found in novice (and even experienced) programmers.
float
can not be used to work with money, it has no precision and is not because it lacks decimal places, could have 30 million decimal places and still have problems. The difficulty is how it is calculated and represented. It is very fast because it is binary but can not represent all possible numbers, so the number you want to store will possibly be represented by another number very close to what you want. This is no problem in most scientific calculations but is impractical for money.
The float
can be displayed with two decimal places but it always has several houses in its representation. And again, this is not what causes the problem.
And it's no use using double
. Not even a superdouble
11.11.2014 / 13:12