C#SUM乘以字段计算 [英] C# SUM multiply calculation over fields

查看:143
本文介绍了C#SUM乘以字段计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据字段1(购买价格)和field2(存储在pergentages中)计算销售价格。我在下面的公式中做错了什么。



简单求和字段1 = 1.00 x 30字段2(30%)=字段3



< pre> 
int a,b;

bool isAValid = int .TryParse(XX_ field1.Text, out a);
bool isBValid = int .TryParse(XX_ field2.Text, out b);

if (isAValid&& isBValid)
{
LB_verkoopprijs.Text =(a * b)。的ToString();
}

else
{
LB_verkoopprijs.Text = 输入无效;
}

解决方案

两种可能性:

1)源代码中的空格正在阻止它正确编译:

  bool  isAValid =  int  .TryParse(XX_ field1.Text, out  a); 
bool isBValid = int .TryParse(XX_ field2.Text, out b);



应该是:

  bool  isAValid =  int  .TryParse(XX_field1.Text, out  a); 
bool isBValid = int .TryParse(XX_field2.Text, out b);





2)文本框不包含整数。

您的示例建议您输入1.00作为field1,它不会解析为整数。

尝试:

  double  a,b; 

bool isAValid = double .TryParse(XX_ field1.Text, out a);
bool isBValid = double .TryParse(XX_ field2.Text, out b);

你可能会得到更好的东西。



但要获得30%的东西,你不想要a * b:购买价格的30%需要a *(b / 100.0),购买价格需要a *(1.0 + b / 100.0)加30%


I would like to calculate a selling price based on field 1 (the purchase price) and field2 (storage in pergentages). What am I doing wrong with the formula below.

Simple sum field1 = 1.00 x 30 field two (30%) = field3

<pre>
int a, b;

bool isAValid = int.TryParse(XX_ field1.Text, out a);
bool isBValid = int.TryParse(XX_ field2.Text, out b);

                            if (isAValid && isBValid)
                            {
                                LB_verkoopprijs.Text = (a * b).ToString();
                            }

                            else
                            {
                                LB_verkoopprijs.Text = "Invalid input";
                            }

解决方案

Two possibilities:
1) The spaces in your source code are preventing it compiling properly:

bool isAValid = int.TryParse(XX_ field1.Text, out a);
bool isBValid = int.TryParse(XX_ field2.Text, out b);


Should probably be:

bool isAValid = int.TryParse(XX_field1.Text, out a);
bool isBValid = int.TryParse(XX_field2.Text, out b);


Or
2) The textboxes don't contain integer numbers.
Your example suggests that you are entering "1.00" as "field1" which will not parse as an integer.
Try:

double a, b;
 
bool isAValid = double.TryParse(XX_ field1.Text, out a);
bool isBValid = double.TryParse(XX_ field2.Text, out b);

And you might get something better.

But to get 30% of something, you don't want "a * b": you need "a * (b / 100.0)" for 30% of the purchase price, or "a * (1.0 + b / 100.0)" for the purchase price plus 30%


这篇关于C#SUM乘以字段计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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