计算发票总额的最准确方法是什么? [英] What is the most accuracy way to calculate invoice Total?

查看:150
本文介绍了计算发票总额的最准确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我计算POS中的总数时,我按如下方式计算,但有时(不是每次)总计算出错,所以我需要最正确的方法来计算发票中的总数。



var_ItemSalePrice是当前商品的商品销售价格的十进制值。

When I do calculate total in POS, I do it as follows, but sometime (not Every Time) total calculation getting wrong, so I need most correct way to calculate total in a invoice.

var_ItemSalePrice is Decimal value for Item Sale price for current item.

TotalText.Text = (ConvertTo.Decimal(TotalText.Text) + var_ItemSalePrice).ToString("###,0.00");





如果在最终确定发票时从sql store程序获得总额?

是否会导致系统变慢?



How about get total from sql store procedure when finalize the invoice ?
Is it cause to slow down the system ?

推荐答案

为什么要将总数保留为文本字符串?

将班级总计保持为十进制或双倍,并加入其中。然后,每次需要显示值时,都可以将其转换为字符串。



将数字保存为字符串是一个糟糕的主意,因为这意味着您每次都会失去精度你保存新值的时间 - 这可能是你得到错误值的原因



从SQL中获取总数也可能是一个好主意 - 假设数据作为数值存储在数据库中,您可以检索总数,但在SQL中将相关列相加并将其作为值返回。但这可能不是一种有效的方法,因为它可能涉及第二轮访问SQL服务器。如果您已经检索了发票行详细信息以便处理成可打印的表单,那么最好将求和保持在本地而不是再次涉及SQL(特别是如果发票行可能有任何机会的话)例如,通过DB上的价格变化,可以同时更改
Why are you keeping the total as a text string?
Keep a class level total as a decimal, or double, and add into that. You can then convert that to a string each time you need to display the value.

Keeping numbers as strings is a poor idea because it means that you risk losing precision every time you save the new value - this is likely to be why you are getting "wrong" values"

Getting the total from SQL may also be a good idea - assuming that the data is stored in the DB as numeric values, you can retrieve the total but summing the relevant columns within SQL and returning it as a value. That may not be an efficient way to do it however, as it may involve a second round trip to the SQL server. If you have already retrieved the invoice line detail for processing into a printable form, it may be better to keep the summation local rather than involving SQL again (especially if there is any chance at all that the invoice lines could be changed in the mean time, by a price change on the DB for example)


这篇关于计算发票总额的最准确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆