Java – double my money: my framework uses doubles monetary amounts

I inherited a project in which monetary quantities use dual types

To make matters worse, it uses twice the money for the framework and its own classes

The framework ORM also handles the retrieval of values from (and stored) to the database In the database, currency values are type numbers (19,7), but the framework ORM maps them to double precision

Without completely bypassing the framework class and ORM, is there anything you can do to accurately calculate the monetary value?

Editor: Yes, I know BigDecimal should be used The problem is that I am closely related to a framework, for example, in this framework, framework com com. pricing. Itempriceinfo has a member double mrawtotalprice; And double mlistprice Our company's application has its own code extension, such as itempriceinfo class

In fact, I can't say to my company, "abolish two years of work and spend hundreds of thousands of dollars on the code based on this framework because of rounding errors."

Solution

If tolerated, consider currency types as one In other words, if you work in the United States, track cents, not dollars, if cents provide the granularity you need Double precision can accurately represent integers up to a very large value (2 ^ 53) (not exceeding the rounding error of the value)

But really, the right thing to do is to completely bypass the framework and use something more reasonable This is an amateur error of the framework – who knows what else is potential?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>