在列表框问题中将变量格式化为货币 [英] Making a Variable be formatted as currency in a list box problem

查看:14
本文介绍了在列表框问题中将变量格式化为货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我将列表框中列出的所有项目都设置为货币格式,而添加的第三个和第四个项目没有显示为货币,即使我的布局与货币相同第一个第二个和第五个选项,它完美地工作.我也不知道如何在列表框中的货币之前添加文本.任何帮助将不胜感激.这是我到目前为止的代码......

I'm having a problem where I'm making all the listed items in a list box be with the format currency and the third and fourth item added are not showing up as currency even though I have it laid out the same with the first second and fifth options and it works perfectly. Also I have no idea how to add text before the currency in the list box. Any help will be greatly appreciated. This is the code I have so far...

        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))

推荐答案

在这两行中,您有效地将值转换为货币,然后将它们相乘,这将再次将它们隐式地转换为数值.所以这两行需要改一下.

In those 2 lines you're effectively converting the values to currency, then multiplying them which will implicitly convert them to just numeric values again. So these two lines need to be changed.

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

这些(注意括号).在您计算出它们的价值之后有效地进行转换.

To these (note the parenthesis). Effectively making the conversion after you've calculated their values.

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

这篇关于在列表框问题中将变量格式化为货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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