C# - 强制String.Format使用小数和从不逗号

Gee*_*esu 6 c# string.format

基本上我意识到我的应用程序使用逗号而不是小数,我从不想允许这个.谁知道我怎么纠正?我无法通过谷歌找到一个强制小数的东西,它只是强迫逗号.

         return String.Format("{0}f, {1}f, {2}f, {3}f, {4}f, {5}f, {6}f, {7}f, {8}f, {9}f, {10}f, {11}f, {12}f, {13}f, {14}f, {15}f", M.M11, M.M12, M.M13, M.M14, M.M21, M.M22, M.M23, M.M24, M.M31, M.M32, M.M33, M.M34, M.OffsetX, M.OffsetY, M.OffsetZ, M.M44);
Run Code Online (Sandbox Code Playgroud)

das*_*ght 9

您可以使用其他重载:

return String.Format(
    CultureInfo.InvariantCulture // <<== That's the magic
,   "{0}f, {1}f, {2}f, {3}f, {4}f, {5}f, {6}f, {7}f, {8}f, {9}f, {10}f, {11}f, {12}f, {13}f, {14}f, {15}f"
,   M.M11, M.M12, M.M13, M.M14, M.M21, M.M22, M.M23, M.M24, M.M31, M.M32, M.M33, M.M34, M.OffsetX, M.OffsetY, M.OffsetZ, M.M44
);
Run Code Online (Sandbox Code Playgroud)

这种调用方式确保将不变文化作为格式提供者传递给String.Format,确保您获得数字的点,货币符号的美元,月份和日期的名称的英语,等等.