C# percentage is 0

前端 未结 6 1209
囚心锁ツ
囚心锁ツ 2021-01-22 08:35

I have a problem when I try to solve simple equation. My equation is find the percentage of student marks. This is my code:

using System;
using System.Collection         


        
6条回答
  •  臣服心动
    2021-01-22 09:13

    The type of a result depends on the variables that are used.

    Any mathematical operation between 2 ints will return an int.
    You need to cast one of them to a decimal before doing the mathematical operation:

     res = (oneee / (decimal)two) * 10;
    

提交回复
热议问题