


Why does the financial system only retain two decimal places? What if there is an amount with more than two decimal places?
I suddenly discovered a problem. The financial system in our lives only has two decimal places at most, such as 12.37, which is accurate to minutes. However, when calculating with two decimal places and non-integers, it will also result in three decimal places, such as the daily rate of a bank. , there will definitely be calculations with three decimal places or more, but why do we only see the balance with two decimal places? Aren’t the extra decimal places also money? Are they omitted? How come they are omitted? I think this question is interesting.
My guess:
In fact, as long as our financial system only uses two decimal places, when more than two decimal places are generated, the following decimal places are not needed, just do not, instead of adding one after five, if one is added, it will cause more money to the user. , even if it is 0.001 yuan more, the loss in the entire system will be huge, so when there are more than two decimal places, we can only directly omit the following decimal places, even if it is 0.239, we must omit 0.009, this 0.009 The loss of RMB 10,000 can only be borne by the user.
For example, bank systems, Alipay, these all have two decimal places. We generally use decimal(10,2)
for the balance field, retaining two decimal places. I suddenly thought of this problem, I am so confused, I don’t know Is it what I thought.
For example, when Alipay uses points and shopping coupons to deduct multiple orders at the same time, the deduction money seems to be split under each order according to the proportion of the order amount, so a decimal appears, but the decimal is also two Well, I haven't paid close attention and I don't know if the deductions for multiple orders add up to the amount deducted when placing the order.
If that’s what I think, then I feel like we must have lost a lot of money a lot of the time? I originally wanted to solve this problem by keeping a few more decimals, but I feel that there may be infinite decimals, which is still unlikely. Will it only cause the user to lose money, even just a little bit.
I hope someone can give me some guidance. I'm so confused. I'm currently encountering this kind of problem in my project.
Thank you!
Reply content:
I suddenly discovered a problem. The financial system in our lives only has two decimal places at most, such as 12.37, which is accurate to minutes. However, when calculating with two decimal places and non-integers, it will also result in three decimal places, such as the daily rate of a bank. , there will definitely be calculations with three decimal places or more, but why do we only see the balance with two decimal places? Aren’t the extra decimal places also money? Are they omitted? How come they are omitted? I think this question is interesting.
My guess:
In fact, as long as our financial system only uses two decimal places, when more than two decimal places are generated, the following decimal places are not needed, just do not, instead of adding one after five, if one is added, it will cause more money to the user. , even if it is 0.001 yuan more, the loss in the entire system will be huge, so when there are more than two decimal places, we can only directly omit the following decimal places, even if it is 0.239, we must omit 0.009, this 0.009 The loss of RMB 10,000 can only be borne by the user.
For example, bank systems, Alipay, these all have two decimal places. We generally use decimal(10,2)
for the balance field, retaining two decimal places. I suddenly thought of this problem, I am so confused, I don’t know Is it what I thought.
For example, when Alipay uses points and shopping coupons to deduct multiple orders at the same time, the deduction money seems to be split under each order according to the proportion of the order amount, so a decimal appears, but the decimal is also two Well, I haven't paid close attention and I don't know if the deductions for multiple orders add up to the amount deducted when placing the order.
If that’s what I think, then I feel like we must have lost a lot of money a lot of the time? I originally wanted to solve this problem by keeping a few more decimals, but I feel that there may be infinite decimals, which is still unlikely. Will it only cause the user to lose money, even just a little bit.
I hope someone can give me some guidance. I’m so confused. I’m currently encountering this kind of problem in my project.
Thank you!
There is a banker rounding method, namely:
When the value of the rounding digit is less than 5, it is discarded directly;
When the value of the rounding digit is greater than or equal to 6, it is rounded after carrying;
When the value of the rounding digit is equal to 5, there are two situations: there is something after 5 Other numbers (non-0) will be rounded and discarded; if 5 is followed by 0 (that is, 5 is the last digit), then whether a carry is needed is determined based on the parity of the digit before 5. Odd numbers will be carried and even numbers will be discarded.
According to the above rules, suppose we require numbers to be accurate to single digits:
<code>49.6101 -> 50 49.499 -> 49 49.50921 -> 50 48.50921 -> 48 48.5101 -> 49</code>
Here is a good example to see the advantages of this calculation method:
2.55 + 3.45 = 6
If we want to retain one decimal place and convert 2.55 and 3.45, it will become like this:
2.6 + 3.5 = 6.1
Obviously this is 0.1 more, then calculate according to our "rounding up to five", 2.55 can actually be said to be 2.550, the 5 we want to round out is followed by 0, then according to the previous The parity of one digit is used to determine whether there is a carry. Obviously, if the front is an odd number, then the carry is 2.6. For 3.45, if the front of 5 is an even number, then it is discarded, and the result is 3.4. Therefore, the calculation of the two is as follows:
2.6 + 3.4 = 6
2016-11-24 Additional instructions
Someone proposed 2.55 + 2.55, which is still an overcount of 0.1. Why didn’t I give this example? Because rounding is used, this situation will also exist. The key point is 2.45 + 2.45, which will be rounded off by conventional rounding. We need to avoid this situation of being close to the middle value without carrying, because only in this way can we ensure that the probability of rounding and carrying in the approximate calculation is equal. This is the main purpose. After all, as long as the accuracy is limited, there must be loss. We only need to ensure that the probabilities are equal under a large number of samples.
The funding issue in this area still needs to consider business needs. According to my previous practice, I saved 4 decimal places. Make a choice based on different scenarios! But all the amounts displayed at the front desk only show 2 digits, and the digits are rounded downSuch as the following scene:
Balance withdrawal, transfer, etc.
Generally, the number
will be rounded down
, for example 10.1234
; then the actual amount of cash that can be withdrawn is 10.12
.
Instalment related
For example, if the total bank limit is 1,000 yuan, and you just buy something, and you spend it all, you can apply for installments. Divided into 3 installments;
According to normal thinking,
1000/3=333.3333333
; after rounding, it becomes 333.33
; when you have paid off all three installments, you find that you only paid 999.99
. This is a trap
The general practice is:
1000-333.33-333.33=333.34
;
Other instructions
Depending on different businesses, the number of reserved digits and trade-offs are different. Such as the net value of the fund. The length of the decimal point still affects the amount of funds greatly. The more accurate this is, the better. Communicate with the product about your specific needs!
Actually, this is not the case. When our e-commerce financial system performs reconciliation and commission calculation, it all reaches the last six digits. decimal(16, 6) will not be rounded until after calculation. Generally, the final rounding step is written in the agreement. I think the last step should fall within the scope of negotiation. It has nothing to do with the system anymore.
I don’t understand very professional things, but I think there is nothing to consider when building a system. All users after two decimal places will lose
If the amount is 0.111, it will be recorded as 0.11
If the amount is 0.111, only 0.11 will be output
It's just that the final points given to the user cannot be cashed out after the calculation. Calculate the final result according to a certain algorithm.
I think it is safer to use cents as the unit of measurement for the amount field stored in the database. In this way, when displaying it at the front desk, round it up first and then divide it by 100 to get the yuan.
The calculation method is "give" and "receive", if the bank is the main body ,
"Give": If the field value is 200.11, then the calculated yuan is 2 yuan and 1.1 cents. This 1.1 cents can be discarded and only give 2 yuan, that is, only the integer part is taken.
"Receive": It can be relatively selfish. In line with the design principle of never losing money, 1 centimeter should be counted as 1 point. Then it is judged whether the field value has a decimal point. If there is a decimal point, round it to +1, if not, just take it. If it is based on rounding. .Masters need to judge and process values with decimal points. Personal preference is the principle of never losing money. This principle should also be a common principle of financial institutions.
The key point is to use cents as the unit of measurement for amounts, if it is hundreds of millions. , you need to consider the Max of the data type, don’t exceed the range.
收款时直接把分以后的数字进位处理,付款时直接截去分以后的小数位。
展示显示2位小数不代表系统中处理都是2位小数吧。我觉得应该会有很多位
要么四舍五入,要么向下取整,保留两位
合理的均分方法可以固定小数位.
比如100元平均分成N份(保留2为小数)并计算尾差:
<code><?php header('Content-Type: text/plain; charset=utf-8'); function tail($num, $fen) { $avg = bcdiv($num, $fen, 2); //除 $tail = bcsub($num, $avg*($fen-1), 2); //减 echo $num.'='.str_repeat($avg.'+', $fen-1).$tail."\n"; echo "$num=$avg*($fen-1)+$tail\n"; return array($avg, $tail); } var_export(tail(100, 3)); var_export(tail(100, 6)); //输出: 100=33.33+33.33+33.34 100=33.33*(3-1)+33.34 array ( 0 => '33.33', 1 => '33.34', ) 100=16.66+16.66+16.66+16.66+16.66+16.70 100=16.66*(6-1)+16.70 array ( 0 => '16.66', 1 => '16.70', )</code>
4舍5入,没有什么好纠结的,相信老祖宗的智慧。
从统计学的角度上来看,在大规模的应用的情况下,你们金融系统多出来的和少掉的钱是近似的,同样的,用户多出来和少掉的钱也是近似的,没有必要纠结。
没有做过金融系统开发,权当抛砖引玉了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Gate.io (Sesame Open Door) is the world's leading cryptocurrency trading platform. This article provides a complete tutorial on spot trading of Gate.io. The tutorial covers steps such as account registration and login, KYC certification, fiat currency and digital currency recharge, trading pair selection, limit/market transaction orders, and orders and transaction records viewing, helping you quickly get started on the Gate.io platform for cryptocurrency trading. Whether a beginner or a veteran, you can benefit from this tutorial and easily master the Gate.io trading skills.

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

This time, the Redstone token $RED will be launched on Binance Launchpool on Binance TGE! This is also the first time Binance has launched a pre-market trading limit mechanism! The first day limit is 200%, and the ban will be lifted after 3 days to avoid "the peak will be achieved when the market opens"! Launchpool mechanism introduces the BinanceLaunchpool participating in Redstone that needs to pledge designated tokens (BNB, USDC, FDUSD) activity period is 48 hours: 08:00 UTC on February 26, 2025 to 08:00 UTC on February 28, 2025 ending this pre-market daily limit rule: 18:00 on February 28, 2025

For investors new to the cryptocurrency world, it is crucial to understand how to buy virtual coins. This article is designed to provide a comprehensive guide to beginners covering detailed steps on how to choose the right exchange, register an account, deposit funds, and purchase Ethereum (ETH). By following this guide, beginners can safely and conveniently embark on their virtual currency investment journey and seize potential investment opportunities in 2025 and beyond.

Alipay and Bitcoin Transactions: A safe and convenient purchasing guide Alipay is a widely used payment tool in China. Although it does not support direct purchase of cryptocurrencies such as Bitcoin, you can complete transactions indirectly through some channels. This article will guide you on how to use Alipay to purchase Bitcoin safely and conveniently, and explain the risks that need to be paid attention to. The most common way to purchase Bitcoin indirectly through cryptocurrency exchanges is to trade through cryptocurrency exchanges that support Alipay. This method usually requires you to buy USDT (stablecoin) first and then exchange USDT for Bitcoin. The following is an example of Ouyi OKX Exchange, explain the operation steps in detail: Register Ouyi OKX account: Visit Ouyi OKX official website (click to register), register an account using email address, and complete

The OKX trading platform offers a variety of rates, including transaction fees, withdrawal fees and financing fees. For spot transactions, transaction fees vary according to transaction volume and VIP level, and adopt the "market maker model", that is, the market charges a lower handling fee for each transaction. In addition, OKX also offers a variety of futures contracts, including currency standard contracts, USDT contracts and delivery contracts, and the fee structure of each contract is also different.

Binance C2C Trading Guide: Safe and convenient way to deposit and withdraw money in cryptocurrency. This article will explain the Binance C2C (CustomertoCustomer) trading model in detail, explain its security, characteristics and operation procedures, and provide graphic tutorials to help you easily master the Binance C2C deposit and withdraw money in ease. What is Binance C2C? Binance C2C is a user-to-user cryptocurrency trading service provided by the Binance platform, providing users with convenient cryptocurrency and fiat currency exchange channels. Launched in 2019, the service supports multiple cryptocurrencies and fiat currency transactions through a peer-to-peer trading model, and provides enhanced security and multiple features. Compared with traditional OTC trading, Binance C2C platform authenticates both parties to the transaction and provides complete support.

This article summarizes eight mainstream digital currency trading platforms including Binance, OKX, Coinbase, Kraken, Gate.io, Bybit, Bitget and KuCoin. The article introduces the establishment time, core advantages and risk warnings of each platform according to four categories: leading exchanges, old-fashioned compliance benchmarks, differentiated platforms and emerging forces, covering a variety of trading types such as spot, futures, and contracts. It focuses on analyzing the application scenarios of USDT trading pairs and the compliance and security of the platform, providing reference for investors to choose a suitable trading platform.
