operator *不能应用于decimal和double c#

时间:2017-12-03 01:14:49

标签: c# tax

我目前正在制作税务计划(学习项目),该计划读取CSV文件并生成人员和帐户余额列表,我需要从一个文本框中向下舍入2个小数位并将其添加到另一个文本框中。我附带的代码告诉我我不能用“*”我怎么用0.1的小数乘以?如果我这样做错了,请告诉我,干杯!

public partial class Form1 : Form
{
    //CSV ARRAY LISTS
    List<string> fullName = new List<string>();
    List<string> accBalance = new List<string>();

    int currentItem;
    int index;
    int counter = 0;

    decimal interestBalance = 0;
    decimal result;

    decimal interestRemainder = 0;
    double round = 0.1;


 private void interestBalanceBox_TextChanged(object sender, EventArgs e)
    {
        interestRemainder = decimal.Parse(interestBalanceBox.Text);
        interestRemainder = Math.Truncate(0.1 * interestRemainder) / 100;
        interestRemainderBox.Text = interestRemainder.ToString();

    }

我们要代表的程序就在这里!任何帮助将不胜感激。

enter image description here

1 个答案:

答案 0 :(得分:5)

interestRemainder = Math.Truncate((decimal)0.1 * interestRemainder) / 100;

您需要将0.1转换为与其他操作数相同的类型