3

我正在开发一个会计应用程序。我有一个交易表,其中一个字段是交易金额(双 10/2 类型)。

对于减少账户余额的交易,最好将交易金额存储为负数,还是将它们全部存储为正数,然后根据交易类型(存款、取款、信用、费用等)将它们转换为负数以进行计算?

谢谢

布雷特

4

2 回答 2

2

I would concur with Catcall and HLGEM. Much better to store them as signed numbers, especially if you're going to do reports that will calculate summaries (aggregates). Having to infer the sign based on another field would make your reports a lot more complex than they should be. Also, many financial functions will require signed numbers (for calculating interest rates for example), and having to derive them from another field would again add some unnecessary complexity.

于 2013-01-28T23:13:31.217 回答
2

最好将正数存储为正数,将负数存储为负数。如果您不预先这样做,您最终将创建一堆修复数字的视图,并重写应用程序代码以使用这些视图。

使用“十进制”或“数字”类型比使用“双精度”要好得多

于 2013-01-28T23:09:56.040 回答