+6

# 3==3.0

Is it true or false

8/30/2019 2:56:55 PM

S_r

+6

+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

+3

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

+3

I mean the value of 20 precision

+3

Is same or vary

+2

The value upto some precision se same or different every time

+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

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?