473,854 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference between int and double???

1 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     double x,i;
  6.     cout<<"Enter the value of the number\n";
  7.     cin>>x;
  8.      for(i=0;i<x;i=i+0.1)
  9.     {                     cout<<"value of i"<<i<<endl;
  10.                           double l=i*i;
  11.                           cout<<"value of square "<<l<<endl;
  12.                           if(x==l)
  13.                           break;
  14.  
  15.     }
  16.     cout<<"the sqrt is "<<i;
  17.  
  18.     system("PAUSE");
  19.     return 0;
  20. }
why I am not getting exact square root if I take x as double,but if I am taking it as int I got the correct result.
Jul 31 '13
15 46857
Naheedmir
62 New Member
Decimal can 100% perfectly represent any number within the precision of the decimal format. In contrast, Float and Double, cannot perfectly represent all numbers, even numbers within their respective formats precision. Int data type is utilized to allocate integer values. It stores 2 bit
Jul 23 '20 #11
cloudytechi147
2 New Member
It usually occupies 32 bits in the computer memory with 4 bytes. An integer can have a maximum value of 2,147,483,647, whereas a float can have a maximum value of 3.4028235 ◊ 1038.

Double is an IEEE 754 64 bits double-precision floating-point format data type, which is also used to represent floating-point numbers. IEEE 754 is a standard representation of floating-point numbers in a computer.

Blog link to know about the difference between float and double.
Nov 22 '21 #12
donbock
2,426 Recognized Expert Top Contributor
As weaknessforcats said 7y ago, the C Standard allows compiler implementations substantial flexibility regarding the internal representation for the various types.

Standard library header <limits.h> provides a method for the compiler implementation to tell an application program some details of the implementation-defined internal representation of integral types.
  • INT_MIN and INT_MAX are the minimum negative / maximum positive values that can be represented by type int.

Standard library header <float.h> provides a method for the compiler implementation to tell an application program some details of the implementation-defined internal representation of floating-point types.
FLT_MIN and FLT_MAX are the minimum/maximum positive values that can be represented by type float.
DBL_MIN and DBL_MAX are the minimum/maximum positive values that can be represented by type double.
LDBL_MIN and LDBL_MAX are the minimum/maximum positive values that can be represented by type long double.

sizeof(typename) tells you how many bytes it takes to represent a number of type typename.
Nov 22 '21 #13
eddparker01
3 New Member
They share certain commonalities, despite their differences at first look. Integral representations exist for floating-point datatypes. Double is simply a double floating-point datatype, while float is a single(?) floating-point datatype. However, just because they have a decimal does not mean they are accurate data types. Use them for approximation rather than precision.
Nov 28 '21 #14
Riya Bajpai
18 New Member
int refers to integer in which we can use whole numbers only where as double is for decimal numbers. For example 1 is an integer and 1.0 is a decimal.
Mar 15 '23 #15
vipulguptaseo
22 New Member
"int" and "double" are data types used in programming languages like C++, Java, and Python, but they represent different values.

"int" is acronym for integer and is used to represent whole numbers (positive, negative, or zero) that do not have a fractional part. In most programming languages, the range of values that can be represented by an "int" is determined by the number of bits used to store it. For example, a 32-bit "int" can represent values from -2,147,483,648 to 2,147,483,647.

On the other hand, "double" is short for double-precision floating-point, and it is used to represent decimal numbers (positive, negative, or zero) that have a fractional part. In most programming languages, a "double" is represented using 64 bits, which allows it to describe a broader range of values than an "int." However, the precision of a "double" is limited by the number of bits used to represent it, so it may not be able to represent very small or huge values with complete accuracy.
Mar 23 '23 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

21
3029
by: b83503104 | last post by:
Hi, Can someone tell me the difference between single quote and double quote? Thanks
15
2249
by: Mohanasundaram | last post by:
Hi All, What is the difference between malloc and calloc other than the point that calloc will initialize the memory to all zeros? This was an interview question for me. All the books and references that I have come across tells that calloc initialize the memory to all zeros. In Herbert Shiltd's C/C++ reference I found that calloc returns a pointer to an array. I want to understand in what way the memory returned by malloc and calloc...
44
16371
by: Daniel | last post by:
I am grappling with the idea of double.Epsilon. I have written the following test: public void FuzzyDivisionTest() { double a = 0.33333d; double b = 1d / 3d; Assert.IsFalse(a == b, "Built-in == operator should not be
21
2860
by: Rich | last post by:
I was considering C# for developing a scientific application, but I have noticed a ~30% difference between VC++ .NET and C# on the same machine, under identical conditions: double a = 0,b = 0, c = 0, d = 0, e = 0; for(int n = 0; n != 6000000; n++) { a = n % 5 *2 / 3 - 4 + 6 / 3 - n + n * 2; b = n * 2.3 - 1 *2 / 3 - 4 + 6 / 3 - n + n * 2; c = n * 3 / 3.5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
2
1622
by: Sanjeev Azad | last post by:
I'm porting my application from VC++ 6.0 to VS .Net and experiencing a difference in the double precisions. I have the following code in my application double val = 16e-6; When I debug it, the debugger shows the value of val as "1.599999999999999e-5", not "1.6000000000000e-5", which is what the debugger shows in VC++6.0.
4
11146
by: Daniel Walzenbach | last post by:
Hi, I wonder if somebody could explain me the difference between Double.Parse and Convert.ToDouble. If I'm not mistaken they are implemented differently (I though for a moment they might be the same like cint(anInt) and cType(anInt, System.Int32) but I checked with ildasm) - if I didn't made a mistake. So when to use which syntax? Is there any performance penalty when using the one over the other or does anybody knows any differences? '...
18
2275
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
7
2718
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards Totto
13
6201
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is ------------------ b += (float)(mode *val); On 32 bit(intel , vs 2003, C++), some watch variables are
6
2925
by: Alexander Stoyakin | last post by:
Hello, please advise on the following issue. I need to check that difference between two double values is not higher than defined limit. int main() { double limit = 0.3; double val1 = 0.5, val2 = 0.2; if ( (val1 - val2) limit )
0
9902
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
11037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10691
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10764
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7083
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5753
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5945
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4165
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.