我的x是12.00,它是一个字符串。我怎样才能去掉点后面的东西呢?
这是一个函数,我必须通过x =>x.Something
x => x.Format(g);
return this;
我看到它可以用Format(g)来完成,但是现在它工作了
可以尝试转换为十进制,如果成功则转换为整型:
Console.WriteLine("input a number:");
string? x = Console.ReadLine().ToString();
int? n = convert(x);
Console.WriteLine(n);
int? convert(string? x)
{
decimal d;
int ? n;
if (Decimal.TryParse(x, out d))
{
n = Decimal.ToInt32(d);
return n;
}
else
return null;
}