Why does formatting a DateTime as a string truncate and not round the milliseconds?

前端 未结 3 653
死守一世寂寞
死守一世寂寞 2021-01-08 01:09

When a Double is formatted as a string rounding is used. E.g.

Console.WriteLine(12345.6.ToString(\"F0\"));

outputs

<         


        
3条回答
  •  悲&欢浪女
    2021-01-08 01:38

    This is a bit subjective, but I would say that rounding date and times values as opposed to truncating them would result in a "more" unexpected behavior.

    For example, rounding new DateTime(2011, 1, 1, 23, 59, 59, 999) would result in a new day completely. This sounds much more weird than just truncating the value.

提交回复
热议问题