如何使用标签以货币格式显示数组列表. [英] How to display an array list in currency format using a label.

查看:102
本文介绍了如何使用标签以货币格式显示数组列表.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建GUI WPF

具有一系列价格.还有2个具有与价格相关的项目的组合框.

Have a array of prices. Also 2 comboboxes having items that correlate to the prices.

 从组合框中选择一个项目后,是否可以用货币格式声明价格的数组列表.

 Is it possible to declare the array list of prices in currency format when an item is selected from the combobox(es).

 

double selection = 0;

double selection = 0;

double [] fruitPrice = {1.95,1.50,1.25,2.95,2.50,1.50};

double[] fruitPrice = { 1.95,1.50,1.25,2.95,2.50,1.50 };

 如果(comboFruit.SelectedIndex!= -1)
             selection + = fruitPrice [comboFruit.SelectedIndex];

小计.Text = Convert.ToString(选择); 

 if (comboFruit.SelectedIndex != -1)
                selection += fruitPrice[comboFruit.SelectedIndex];

Subtotal.Text = Convert.ToString(selection);  

单击按钮
小数小计= Convert.ToDecimal(小计.);
小数总数;
          
总计=小计;
Total.Text = Convert.ToString(总计);

Subtotal.Text = String.Format("{0:C}",小计);
总计.Text = String.Format("{0:C}",total);
               ;       

CLICK BUTTON
decimal subtotal = Convert.ToDecimal(Subtotal.Text);
decimal total;
           
total = subtotal;
Total.Text = Convert.ToString(total);

Subtotal.Text = String.Format("{0:C}",subtotal);
Total.Text = String.Format("{0:C}",total);
                        

此功能有效,但是当我添加两个或多个项目时,不会以货币格式显示我的价格数组.

this work but doesn''t display my array of price in currency format when I add two or more items.

 

请使用任何解决方案.

Any solution please.

推荐答案

要将项目显示为货币,请构建一个使用ToString重载的字符串列表,该字符串显示货币格式.或者,您也可以为控件编写一种样式,以该格式显示数据.现在,您还没有编写任何代码来尝试做您想做的事情,所以毫不奇怪,它行不通.

To display the items as currency, build a list of strings which use the ToString overload that shows in currency format.  Or you may be able to write a style for your control which shows the data in that format.  right now, you have not written any code to attempt to do what you want, so no surprise it doesn''t work.

此外,如果您使用的是WPF,请添加WPF标签,以便寻求WPF帮助的人们都可以找到它.

Also, if you''re using WPF, add the WPF tag, so people searching to help with WPF will find it.


这实际上是可行的,但只是在想插入位置string.format("{0:C}",selection);
This actually works but just wondering where to insert  string.format("{0:C}", selection);


如果您无法定义用于格式化的模板,字符串集合或具有属性的类的集合,您可以使用该属性来显示其格式.

If you can''t define a template to format it, I''d do a collection of strings, or a collection of a class which has a property you can use to display that formats it.


这篇关于如何使用标签以货币格式显示数组列表.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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