有什么不对这种划分? [英] What's wrong with this division?

查看:136
本文介绍了有什么不对这种划分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为有很多关于我了解的数据类型。
为什么发生这种情况。

I think there's a lot for me to learn about data types. Why this happens

double result = ((3/8)*100).ToString();



它给零..应该是37,5 ...:(

it gives zero .. should be 37,5 ... :(

推荐答案

3/8执行整数除法,结果为0

3/8 performs an integer division and the result is 0

double result = ((3.0/8)*100);

应该这样做

顺便说一句,如果你这样做((3.0 / 8)* 100)的ToString()你得到一个字符串,而不是一个双。

By the way, if you do ((3.0/8)*100).ToString() you get a String and not a double.

这篇关于有什么不对这种划分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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