Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何删除C#中值后的小数位?_String_C# 4.0_Decimal - Fatal编程技术网

String 如何删除C#中值后的小数位?

String 如何删除C#中值后的小数位?,string,c#-4.0,decimal,String,C# 4.0,Decimal,让我有一个十进制值14.8447,我需要字符串中的这个值8447 有人能帮我找到使用窗体C的方法吗?您可以使用类似以下的方法: decimal d = 14.8447m; string s = d.ToString(CultureInfo.InvariantCulture); string t = s.Substring( s.IndexOf('.')+1); (尽管我认为我的代码有点像黑客) 要使其更具防错性,您可以编写: decimal d = 14.8447m; string s = d

让我有一个十进制值
14.8447
,我需要字符串中的这个值
8447


有人能帮我找到使用窗体C的方法吗?

您可以使用类似以下的方法:

decimal d = 14.8447m;
string s = d.ToString(CultureInfo.InvariantCulture);
string t = s.Substring( s.IndexOf('.')+1);
(尽管我认为我的代码有点像黑客)

要使其更具防错性,您可以编写:

decimal d = 14.8447m;
string s = d.ToString(CultureInfo.InvariantCulture);

int index = s.IndexOf('.');
string t = index >= 0 && index + 1 < s.Length
       ? s.Substring(index + 1)
       : string.Empty;
这是一个.string.Format(“{0:0.0000}”,14.8447m).Split(“,”,“。”).Last()可以是这样的:

decimal Numero = 8.24M;
string r = (Numero - Math.Floor(Numero)).ToString().Replace("0.", "");

我想很容易

无论如何,操纵字符串是最容易的。我不会说这是一个“黑客”。奥德,我用下面的代码@Uwe-Keim-thanks解决了它,这不是我问题的重点。我们希望人们在提问之前做出努力,并在提问中展示他们的努力。好吧,很抱歉,这是一篇旧文章,我没有提醒我尝试了什么,但下次我肯定也会发布我的代码。。
decimal Numero = 8.24M;
string r = (Numero - Math.Floor(Numero)).ToString().Replace("0.", "");