How to format floating point value with fix number of digits?

前端 未结 3 1997
借酒劲吻你
借酒劲吻你 2021-01-29 06:41

Is it possible in C# to format a double value with double.ToString in a way that I have always a fixed number of digits, no matter on which side of the decimal point?

Sa

3条回答
  •  孤城傲影
    2021-01-29 07:10

    If your goal is to avoid "jumping" of the decimal point:

    1. Use g formating, this does the most sensible thing to do
    2. See where the decimal point is in your resulting string
    3. pad with spaces at the beginning to align the column at the decimal point

提交回复
热议问题