Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

keymoon's blog

By keymoon, history, 7 years ago, In English

Code 1.

using System;

class P
{
    static void Main()
    {
        double d = 1.23456;
        Console.WriteLine(d);
    }
}

Code 2.

using System;
class P
{
    static void Main()
    {
        double d = 1.23456;
        Console.WriteLine(d);
    }
}

Can you find difference between two?

Yes,It was JUST line feed. And,these two code lead to a different result.

Result 1.1,23456

Result 2.1.23456

It seems '.' replaced by ','.

The same problem occurs in Mono.

I highly recommend to use substitute methods like this:

static string doubleToString(double d)
{
    int s = (int)d;
    string a = Convert.ToInt32((d - s) * 1000000000).ToString().PadLeft(9, '0');
    return $"{s}.{a}";
}

edit. This issue is not a bug. Thank you for teaching me AlexDmitriev, Gassa.

This is locale problem. I am using "Ja" locale, but I should use "en_US" locale.

Proof: 33796322 33796340

  • Vote: I like it
  • +18
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by keymoon (previous revision, new revision, compare).

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I'm pretty sure the difference not in newline but in invoker configuration (namely, locale). You can force en_US locale to use .

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Perhaps for one of these programs, the resulting executable or its output was cached at the moment when the default locale had , instead of ..