使变量在列表框中出现格式为货币的问题

时间:2018-11-13 20:32:19

标签: vb.net

我遇到了一个问题,就是我要使列表框中的所有列出项目都具有货币格式,并且即使我将其与第一个和第二个项目相同,添加的第三个和第四个项目也不会显示为货币第一个第二和第五个选项,并且效果很好。另外我也不知道如何在列表框中的货币之前添加文本。任何帮助将不胜感激。这是我到目前为止的代码...

        Dim intCost1, intcost2, intcost3, intcost4 As Single

    'This code does the maths and breaks down the costs of the insurance so the employee can easily the cost to the customer
    lstCostBreakDown.Items.Clear()
    'This is the inital quote before any add ons or reductions
    lstCostBreakDown.Items.Add(FormatCurrency(intFinalVal))
    intCost1 = (FormatCurrency(intFinalVal))
    'This is the cost of the add on 
    lstCostBreakDown.Items.Add(FormatCurrency(sngAddOn * intFinalVal))
    intcost2 = (FormatCurrency(sngAddOn * intFinalVal))
    'This is the reduction you get for private health insurance 
    lstCostBreakDown.Items.Add(FormatCurrency(intFinalVal * sngAddOn + intFinalVal) * sngHealthInsurance)
    intcost3 = (FormatCurrency(intFinalVal * sngAddOn + intFinalVal) * sngHealthInsurance)
    'This is the amount of VAT the customer has to pay 
    lstCostBreakDown.Items.Add(FormatCurrency(intCost1 + intcost2 - intcost3) * 0.2)
    intcost4 = (FormatCurrency(intCost1 + intcost2 - intcost3) * 0.2)
    'This is the subtotal of all costs and reductions 
    lstCostBreakDown.Items.Add(FormatCurrency(intCost1 + intcost2 - intcost3 + intcost4))

1 个答案:

答案 0 :(得分:0)

在这两行中,您实际上是在将值转换为货币,然后将它们相乘将再次隐式地将其转换为仅数字值。因此,这两行需要更改。

lstCostBreakDown.Items.Add(FormatCurrency(intFinalVal * sngAddOn + intFinalVal) * sngHealthInsurance)
lstCostBreakDown.Items.Add(FormatCurrency(intCost1 + intcost2 - intcost3) * 0.2)

对此(注意括号)。有效地在之后进行了转换,您已经计算了它们的值。

lstCostBreakDown.Items.Add(FormatCurrency((intFinalVal * sngAddOn + intFinalVal) * sngHealthInsurance))
lstCostBreakDown.Items.Add(FormatCurrency(intCost1 + intcost2 - intcost3) * 0.2)
相关问题