我的数字是0.15,但我只想显示15。 我怎么做? *我需要解决方案以匹配每个数字(例如:0.234到234、0.3到3等) 谢谢你的帮手...
答案 0 :(得分:0)
这种方式:
class Program
{
static void Main(string[] args)
{
double number = 1.234;
number = GetDecimalPart(number);
float number1 = 1.234f;
number1 = GetDecimalPart(number1);
decimal number2 = 1.234m;
number2 = GetDecimalPart(number2);
}
private static double GetDecimalPart(double number)
{
string strNumber = number.ToString(CultureInfo.InvariantCulture);
strNumber = strNumber.Substring(strNumber.IndexOf(".") + 1);
return double.Parse(strNumber);
}
private static float GetDecimalPart(float number)
{
string strNumber = number.ToString(CultureInfo.InvariantCulture);
strNumber = strNumber.Substring(strNumber.IndexOf(".") + 1);
return float.Parse(strNumber);
}
private static decimal GetDecimalPart(decimal number)
{
string strNumber = number.ToString(CultureInfo.InvariantCulture);
strNumber = strNumber.Substring(strNumber.IndexOf(".") + 1);
return decimal.Parse(strNumber);
}
}