c#的工作百分比

本文关键字:百分比 工作 | 更新日期: 2023-09-27 17:48:59

我有两个值,一个是十进制值另一个值的值将计算小数的百分比例如:

60% = 6

decimal value1 = 10;
decimal percentage = 60;
textbox1.text = ("mathsum here").toString();

如何使用十进制值和包含百分比值的值来计算该值?

c#的工作百分比

number * percentage / 100

10 * 60 / 100 = 6

也许这样想会对你有帮助。

<>之前6——= 0.6(或相当于你的60%)10之前

在你的例子中,你想知道如何计算分子(6),所以给它分配一个变量。让我们使用x

<>之前X——= .610之前

. .并通过两边乘以10(在你的情况下)来解出X。

<>之前X * 10 = .6 * 10------10X = .6 * 10之前

从这里我希望你能看到你可以把你的百分比值乘以你的小数值。

注意,为了得到。6,你需要将你的百分比(60)除以100。

所以我们的最终公式是: <>之前60——* 10One hundred.之前

或使用变量:

<>之前百分比---------- * value1One hundred.之前

我希望我已经增加了你的理解,即使我的公式是类似于前面的答案。我想确保你理解这个公式是如何推导出来的。

祝你好运!

var result = (percentage/100) * value1;
textbox1.Text = result.ToString();

你是说这样吗?

textbox1.text = (value1 * percentage/100).ToString();
顺便说一下,toString在c#中写成ToString,大写的T
var answer = value1 * (percentage/100);

获取金额的百分比

decimal Value = 1200;
int percentage = 20; //20%
var result=(percentage/100)*(Value);

这难道不是

percentage/100m*value

?

我会将关注点分开:

  1. 计算原始小数的一部分:

  2. 提供适当的格式化程序以百分比形式输出结果:

    text = result.ToString("0.0%");

http://www.dotnetperls.com/percentage

from question it self answer is clear

60%表示60/100,然后用值

计算

60/100 * 10 = 6使用逻辑变量

 textbox1.Text = ((percentage /100) * value).ToString();

 textbox1.Text = ((percentage * .01 ) * value).ToString();

你需要除以100