Understanding the datatype Double

2019-09-10 02:41发布

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?

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

标签: double
1条回答
Root(大扎)
2楼-- · 2019-09-10 03:07

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.

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

查看更多
登录 后发表回答