+5

3==3.0

8/30/2019 2:56:55 PM

SAHIL

10 Answers

New Answer

+5

What about this 0.1+0.2==0.3

+3

SAHIL true integer 3 will be converted to double 3.0 before comparison. Though all doubles and float values cannot always be represented accurately, but whole numbers are usually represented accurately hence comparison will be true

+2

After Decimal there is 0s only or can be anything?

+2

I mean the value of 20 precision

+2

Is same or vary

+1

SAHIL They are not the same. As i told you not all float and double values can be represented accurately try this printf("%.20f", 0.1); printf("%.20f", 0.2); printf("%.20f", 0.3); You will see the actual values and know why they are not equal. .20f is precesion of 20 digits after decimal points

+1

SAHIL Up to you how many digit precision you want. if you just do printf("%f", 0.1); then the default precesion is of 6 digits. You can use any precesion you want. I do not remember the max precision

+1

The value upto some precision se same or different every time

+1

SAHIL Same, why do you think it would be different. Think youself if they were different then you cannot rely on floating point calculations at all. The calculations can be different between two compilers for the same precision if they use different floating point Standard see this for more information https://en.m.wikipedia.org/wiki/Floating-point_arithmetic

0

SAHIL I didn't get you if you print 0.1 with 20 digit precision you get 0.10000000000000000555 what exactly do you want to know?