Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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
如何将C#中的44/5转换为十进制值?_C#_Asp.net - Fatal编程技术网

如何将C#中的44/5转换为十进制值?

如何将C#中的44/5转换为十进制值?,c#,asp.net,C#,Asp.net,如何在C#中转换44/5以获得十进制值实际结果将是这样的13.75,但我只得到了13 需要13.75如何获得 尝试了许多解决方案,但无法获得,请帮助查找 -----------尝试过的方法-------------------- protected void txtbox_TextChanged(object sender, EventArgs e) { int cal= 55 / 4; //13 decimal cal= 55 / 4; //13 string

如何在C#中转换44/5以获得十进制值实际结果将是这样的13.75,但我只得到了13

需要13.75如何获得 尝试了许多解决方案,但无法获得,请帮助查找

-----------尝试过的方法--------------------

protected void txtbox_TextChanged(object sender, EventArgs e)
{
    int cal= 55 / 4;  //13

    decimal cal= 55 / 4;  //13

    string cal= String.Format("{0:0.00}", 55 / 4);  //13.00

    decimal cal= decimal.Floor(55 / 4);     //13

    SalesPrice.Text = cal.ToString();
}

尝试执行:
decimal cal=55m/4

将其更改为:

decimal cal= (decimal)55 / 4;  //13.75

您正在执行整数运算。将任一操作数设为十进制,例如
55m/4
。(这是许多问题的重复,但我现在没有时间找到。)你试过55/4.0或55.0/4吗?@captainsac:这会给出一个双倍的结果;OP需要一个
十进制
。没关系。她希望结果是13.75。。可以更改cal变量的数据类型。@captainsac:或者将您使用
double
literal的建议改为使用
decimal
literal…谢谢使用您的想法得到了答案。您的想法也行得通,谢谢