If float and double are not accurate, how do banks make accurate money settlements?

C ++ is currently being studied, and it just happened. I'm just curious, as I'm going to develop a simple banking program. I will use doubleto calculate the dollar / interest rate, etc., But there are some slight differences between computer calculations and human calculations.

I believe these extra pennies in the real world can make a difference!

+5
source share
4 answers

In many cases, financial calculations are performed using fixed-point arithmetic instead of floating point.

, .NET Decimal VB6 Currency. , , , $.0001.

, , . - ( %, , , $y ).

+12

8 : -9223372036854775808 max: 9223372036854775807 /, // .

+1

. , ( ): , , , , .

, double , ... - (, ), , , , ( - , ). - Decimal , . (, ), double .

+1

Just because a number is not an integer does not mean that it cannot be accurately calculated. Consider that the value in dollars and cents is an integer if you count the number of pennies (cents), so for a fixed-point library, just use two decimal places of precision to just multiply each number by 100, do the calculation as an integer, and then again divided by 100.

0
source

All Articles