通过除以两个int得到一个double [英] Get a double by dividing two int

查看:127
本文介绍了通过除以两个int得到一个double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能看起来非常基本......几乎羞于问道。



但我希望通过将整数除以另一个整数得到一个双精度数。



我想这样做0.8



但是我注意到它没有返回4/5我只试过:


p $ p>双倍得分;
得分= 4/5 * 100;

解决方案

 double score =(double)4 /(double)5 * 100; 


这也应该有效

  double 得分=( double )4/5 *  100 ; 


this may seemed very basic...almost ashamed to asked.

But I want to get a double by dividing an integer by another integer.

I want to 0.8 by doing this

but I notice it is not returning the 4/5 only whole numbers.

What I have tried:

double score;
             score = 4/5*100;

解决方案

double score = (double)4 / (double)5 * 100;


This should work too

double score= (double)4/5 * 100;


这篇关于通过除以两个int得到一个double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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