当前位置:网站首页>How to solve the problem of amount accuracy in financial applications (take quorum and golang as examples)
How to solve the problem of amount accuracy in financial applications (take quorum and golang as examples)
2022-06-22 14:04:00 【Zhengzezhou】
Amount accuracy problem
background : This paper focuses on the application of enterprise blockchain Quorum As an example ( The application is powered by golang To write ), It explains how to solve the problem of amount accuracy .
The problem of amount accuracy is a problem that every financial system developer has to face , From the beginning of my career , From banking system , Internet payment company system , Until blockchain financial application , This problem is everywhere . The typical solutions to this typical problem are as follows .
Specific examples
ICBC account gold application ( Real applications ) The amount unit of is defined as float64, What problems will be caused in practice ?effective java Someone mentioned this problem , Will cause the following serious consequences ( I use golang Rewrite as follows ):
package main
import "fmt"
const TEN_CENTS float64 = 0.1
func main() {
var itemBought int = 0
var myfund float64 = 1.00
for price := TEN_CENTS; price < myfund; price += TEN_CENTS {
itemBought++
myfund -= price
fmt.Println("loop")
}
fmt.Println(" What you buy :", itemBought, " Remaining amount :", myfund)
}
If you use **“go run”** Command to run this file will have the following prompt output
[email protected]:~/gopath$ go run currency.go
loop
loop
loop
What you buy : 3 Remaining amount : 0.3999999999999999
Why? ? Namely float64 In fact, it is not suitable for currency
The author of this question in the same series of blog 《 Ten questions about the safety of financial application fund processing 》 There is elaboration , See para 6 spot
that Quorum How to solve the problem ?
First , The expression of currency is international standard
Considering the different situations between countries , There are different forms of money , Will be in xml In the definition of
<currencies>
<currency type="USD">
<displayName>Dollar</displayName>
<symbol>$</symbol>
</currency>
<currency type ="JPY">
<displayName>Yen</displayName>
<symbol>¥</symbol>
</currency>
<currency type="PTE">
<displayName>Escudo</displayName>
<symbol>$</symbol>
</currency>
</currencies>
secondly , The smart thing to do is to avoid this problem , Like bitcoin , direct There is no decimal point , With Wei In units of , And it cannot be subdivided .
See the following code (core/types/transaction.go)
Amount *big.Int `json:"value"
So they all introduce math.big package , There is no decimal point
What about RMB ?
Define the form , For example, the smallest is a fraction , All the operations are unified and divided into two parts , And then calculate
The process is similar to the following :
transformation – 》 Calculation – 》 transformation
The problem of currency accuracy has been solved in previous blockchain applications
The currency Super precision ,38 position , Other things like Ethereum , It's all about taking math.bigInt,wei Is the smallest non subdivisible
Fabric Is to build the bottom channel, Certificates and so on , There is no amount involved , This problem is thrown to the application layer
The debate on the route of bank application to amount processing :
International trade settlement application : Set a special amount class , A signed , There are decimals , Yes complex Calculation rules
Host core system application : Only deal with RMB , So it's all set to points , Simplification rules
In the future, our application system , It is suggested that the first scheme be adopted , Internationalization is supported initially , As for the increased amount of calculation , In fact, the main performance bottleneck is not here
边栏推荐
- 天润云上市在即:VC大佬田溯宁大幅减持,预计将套现2.6亿港元
- Oracle user space statistics
- Leetcode math problems
- Microservice test efficiency governance
- Double hands of daily practice of Li Kou 2day9
- 史蒂芬·柯维写给年轻人的高效工作秘笈
- 程序员要不要选择软件人才外包公司?
- 技术实践 | 场景导向的音视频通话体验优化
- 金融应用如何解决金额精度问题(以Quorum、golang为例)
- Rigid demand of robot direction → personal thinking ←
猜你喜欢

Configuring cplex12.4 tutorial in VS2010

"Dare not doubt the code, but have to doubt the code" a network request timeout analysis

Tasks and responsibilities of the test team and basic concepts of testing

HW is around the corner. Can't you read the danger message?

CVE-2022-22965複現

Oceanbase database helps the ideal automobile intelligent production line to realize automatic recovery within 30 seconds

HMS Core新闻行业解决方案:让技术加上人文的温度

Simple integration of client go gin IX create

JS advanced programming version 4: learning iterators

如何给VR全景作品添加遮罩?作用是什么?
随机推荐
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
Stephencovey's tips for efficient work for young people
Double hands of daily practice of Li Kou 2day9
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
浅析Redis 切片集群的数据倾斜问题
金融应用如何解决金额精度问题(以Quorum、golang为例)
Getting started with shell Basics
天润云上市在即:VC大佬田溯宁大幅减持,预计将套现2.6亿港元
Processing statement on price selection of several manufacturers
Microservice test efficiency governance
性能相关指标
Interpretation of the thesis -- factorization meets the neighborhood: a multifaceted collaborative filtering model
[cloud native] event publishing and subscription in Nacos -- observer mode
CVE-2022-22965复现
“不敢去怀疑代码,又不得不怀疑代码”记一次网络请求超时分析
毕业论文写作中致谢词的常见写法及优秀范文
Nine good programming habits for 10 years
JSP based library management system, including source code, database script, video tutorial for project operation, and video tutorial for thesis writing
Temporary recommendation on graphs via long- and short term preference fusion
Talk about row storage and column storage of database