Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя keymoon

Автор keymoon, история, 7 лет назад, По-английски

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

  • Проголосовать: нравится
  • +18
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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