Real literals

  • Thread starter Thread starter Clive Dixon
  • Start date Start date
C

Clive Dixon

I came across the following code:

double d = 004166666667;

(i.e. no decimal point) which parses the literal as 0.04166666667, with a
decimal point. How so? The literal 004166666667 doesn't even look like a
valid real literal to me according to ECMA-334 section 9.4.4.3, so I would
have thought it would be treated as an integer literal, parsed as such and
the value undergo a straight integer -> double conversion.
 
Clive Dixon said:
I came across the following code:

double d = 004166666667;

(i.e. no decimal point)

double d = 004166666667;
Console.WriteLine(d);
Console.WriteLine(++d);

returns:
4166666667
4166666668
(checked on English and Polish regional settings)

RGDS PSG
 
My apologies - found a place elsewhere in the code where the (static) value
happened to be set to 0.04166666667, which caused my confusion. The original
assignment is indeed incorrect.
 
Back
Top