为什么我不能用智力得到的百分比 [英] Why I cannot the get percentage by using Int

查看:116
本文介绍了为什么我不能用智力得到的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅我的编程知识。我知道这是一个简单的事情,但我不明白,为什么结果总是0,为什么小数将被罚款?

Please forgive my programming knowledge. I know this is a simple thing, but I do not understand why result is always 0. Why decimal will be fine?

int a = 100;
int b = 200;
decimal c = (a / b) * 100;



非常感谢。

Many thanks.

推荐答案

整数除法总是截断其余部分。这是在该号码划分的时间内完成,的的时候它赋值给变量(如我猜你假设)。

Integer division always truncates the remainder. This is done at the time that the number is divided, not when it's assigned to the variable (as I'm guessing you assumed).

decimal c = ((decimal)a / b) * 100;

这篇关于为什么我不能用智力得到的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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