了解数据类型Double [英] Understanding the datatype Double

查看:105
本文介绍了了解数据类型Double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用C编写程序以获取数组中偶数的百分比。我正在考虑使用int数据类型编写它。但是使用double告诉我的某些对象会更容易。我不明白有人可以指导我吗?

I am trying to write a program in C to get the percent of even numbers in an array. I am thinking of writing it using int datatype. But some one mentioned to me using double will be easier. I don't understand that. Can anyone guide me with it?

double数据类型返回什么?
return语句可以作为return(double)给出吗?那会给什么?
可以将实数加倍转换成百分比吗?例如:0.5到50.0

What does double datatype return? Can the return statement be given as return (double)? What will that give? Can double convert a real number to a percent? Eg: 0.5 to 50.0

推荐答案

int 数据类型与名称将暗示整数(或整数)。因此,您不能表示像 0.5 这样的小数。 double 是十进制数字。因此,您可以保存数字 0.5 。通常的做法是将百分比存储为简单的十进制数字,例如 0.5 (使用 double 类型)。然后,当您需要很好地显示为 50.0%时,只需在显示前乘以 100 即可。

The int datatype is, as the name would suggest, integers (or whole numbers). So you cannot represent a decimal like 0.5. A double is decimal number. So you can hold numbers like 0.5. Common practice is to store your percentage as a simple decimal number like 0.5 (using the double type). Then when you need to display nicely as 50.0%, just multiply by 100 before displaying.

以下是C的基本数据类型的有用链接: http:// www .tutorialspoint.com / ansi_c / c_basic_datatypes.htm

Here's a useful link on C's basic datatypes: http://www.tutorialspoint.com/ansi_c/c_basic_datatypes.htm

这篇关于了解数据类型Double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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