来自C#中Datagridview的标签中的总价

时间:2018-11-04 13:51:13

标签: c# winforms

这里是C#中总价格的计算方式,我想在标签Like in an image below中显示产品的总价格

带有SalesForm.TotalPrice的行将计算总价格:

if (cbxProdTypeSwitch.SelectedIndex == 0)
{
    // phones 
    Smartphone ph = (Smartphone)dgvProds.SelectedRows[0].DataBoundItem;

    SalesForm.productName = ph.ProductName;
    SalesForm.price = ph.price;
    SalesForm.totalPrice = ph.price * Convert.ToInt32(nudAmount.Value);
    SalesForm.salesDate = DateTime.Now;
    SalesForm.amount = Convert.ToInt32(nudAmount.Value);
    SalesForm.clientName = tbxClient.Text;
}

2 个答案:

答案 0 :(得分:0)

如果要将int或double值显示为label1.Text = SalesForm.totalPrice.ToString(); , 那么您应该这样做:

INT

label1.Text = SalesForm.totalPrice.ToString("0.00"); //for currency
label1.Text = SalesForm.totalPrice.ToString("0.##"); //if you want to eliminate the ".00"

双重

from csv import reader
from statistics import median
from collections import defaultdict

data = defaultdict(list)
with open('data.csv') as file:
    csv_reader = reader(file)
    headers = list(map(str.strip, next(csv_reader)))

    for line in csv_reader:
        for col, value in enumerate(map(str.strip, line)):
            data[headers[col]].append(value)

medians = {k: median(map(float, v)) for k, v in data.items() if k.startswith('A')}

print(medians)

答案 1 :(得分:0)

如果要使用货币,请使用命名格式。

label1.Text = $"{SalesForm.totalPrice:C2}";