我想从十进制创建一个字符串,而不是小数点分隔符;
1,500.00应变为“150000”。
这是什么格式? (Whithout string.replace,和。)
谢谢!
答案 0 :(得分:7)
尝试:
decimal d = 1500m;
string s = (100*d).ToString("0");
答案 1 :(得分:2)
两种解决方案:
.ToString("0")
答案 2 :(得分:1)
String.Replace
有什么问题?这很简单,重点:
CultureInfo info = CultureInfo.GetCultureInfo("en-US");
decimal m = 1500.00m;
string s = m.ToString("G", info).Replace(".", String.Empty));
Console.WriteLine(s); // outputs "150000"
m = 1500.0m;
string s = m.ToString("G", info).Replace(".", String.Empty));
Console.WriteLine(s); // outputs "15000"
m = 1500.000m;
string s = m.ToString("G", info).Replace(".", String.Empty));
Console.WriteLine(s); // outputs "1500000"
m = 1500.001m;
string s = m.ToString("G", info).Replace(".", String.Empty));
Console.WriteLine(s); // outputs "1500001"
m = 1500.00000000000000000000001m;
string s = m.ToString("G", info).Replace(".", String.Empty));
Console.WriteLine(s); // outputs "150000000000000000000000001"
答案 3 :(得分:0)
decimal value = 1500;
Console.WriteLine((value * 100).ToString("0"));