Double.ToString格式化 [英] Double.ToString for formatting

查看:111
本文介绍了Double.ToString格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要格式化一批具有特定的格式。我不希望的格式决定与计算机的区域设置,所以我想:

I need to format a number with a specific format. I don't want to decide on the format with the regional settings of the computer so I'm trying:

string s = "219171"
string result = Convert.ToDouble(s).ToString("0,0.0") //219,171.0
string result = Convert.ToDouble(s).ToString("0.0,0") //219171.00

我要显示为

219.171,00

219.171,00

感谢您

推荐答案

创建自定义的NumberFormatInfo实例,并传递调用toString时()。

Create a custom NumberFormatInfo instance and pass that in when calling ToString().

NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberGroupSeparator = ".";
nfi.NumberDecimalSeparator = ",";

double s = 219171;
string result = s.ToString("N2", nfi);

的NumberFormatInfo 属于 System.Globalization

这篇关于Double.ToString格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆