1

double 値があり、デフォルトの 15 桁を超える文字列に変換したいと考えています。どうすればこれを達成できますか?

(1.23456789987654321d).ToString(); // 1.23456789987654
(12.3456789987654321d).ToString(); // 12.3456789987654
(1.23456789987654321d).ToString("0.######################################"); // 1.23456789987654
(1.23456789987654321d).ToString("0.0000000000000000000000000000000"); // 1.2345678998765400000000000000000
4

2 に答える 2

2

15 桁を超える精度をサポートしていないため、double では使用できません。10 進数データ型を使用してみることができます。

using System;

namespace Code.Without.IDE
{
    public class FloatingTypes
    {
        public static void Main(string[] args)
        {
            decimal deci = 1.23456789987654321M;
            decimal decix = 1.23456789987654321987654321987654321M;
            double doub = 1.23456789987654321d;
            Console.WriteLine(deci); // prints - 1.23456789987654321
            Console.WriteLine(decix); // prints - 1.2345678998765432198765432199
            Console.WriteLine(doub); // prints - 1.23456789987654
        }
    }
}
于 2013-04-03T22:22:59.593 に答える