本文介绍了用剃刀(包括小数)的形式计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的这一切和我真的在努力寻找什么,我试图做任何的例子。

I am fairly new to all of this and am really struggling to find any examples of what I am trying to do.

我想要创建一个简单的,你输入一些细节,并进行计算就可以了。

all I want to create is a simple for where you enter some details and it performs a calculation on it.

我可以尽可能获得尽可能加法和乘法等。但它会得到一个十进制的答案出来,我可以得到它的工作。

I can get as far as adding and multiplying etc.. but when it comes to getting a decimal answer out I can get it to work.

和作为一个额外的,我想用一个下拉作为一个变量说做一次计算基础上,下拉说* 1.4如果男性和* 1.01如果女性

and as an extra i want to use a drop down as a variable say do one calculation based on the drop down say * 1.4 if its male and * 1.01 if its female

是我迄今为止

@{
    var total = 0;
    var totalMessage = "";
    if(IsPost) {

        var age_= Request["frmage"];
        var weight_ = Request["frmweight"];
        var SerCre_ = Request["frmSerCre"];
        var sexfactor_ = Request["frmGender"];

        var age = age_.AsInt();
        var weight= weight_.AsDecimal();
        var SerCre = SerCre_.AsDecimal();



        total =   (((140-age)*weight)*sexfactor)/SerCre ;
        totalMessage = "Total = " + total;
    }
}


 <form method="post">
    <p><label for="text1">Age:</label>
      <input type="text" name="frmAge" size="3"/>Years
    </p>
    <p><label for="text2">Weight:</label>
      <input type="text" name="frmWeight" />in Kg (1st = 6.35kg)
    </p>
    <p><label for="text3">Serum Creatinine:</label>
      <input type="text" name="frmSerCre" /> μmol/L
    </p>
   <p><label for="text4">Gender:</label>
      <select name="frmGender" id="select">
        <option value="M" >Male</option>
        <option value="F" >Female</option>
      </select>


    </p>
    <p><input type="submit" value="Calculate" /></p>
  </form>

  <p>@totalMessage</p>

一些帮助,即时通讯可能会在完全错误的方式了!

some help im probably going about it in the completely wrong way!

推荐答案

就行了哪里是说:

totalMessage = "Total = " + total;

试试这个来代替:

Try this instead:

totalMessage = "Total = " + total.ToString("0.00");

让我知道有没有什么帮助。

Let me know if that helps.

古德勒克?

=======================================

=======================================

下面是code我有工作在我的机器上:

Here is the code I have working on my machine:

@{

无功总=0米;

    var totalMessage = "";
    if (IsPost)
    {
        var age = Request["frmage"].AsInt();
        var weight = Request["frmweight"].AsDecimal();
        var SerCre = Request["frmSerCre"].AsDecimal();
        var sexfactor = Request["frmGender"].AsBool();
        total = Convert.ToDecimal(age*SerCre);
        totalMessage = "Total = " + total.ToString("0.00");
    }
}

<form method="post">
<p>
    <label for="text1">Age:</label>
    <input type="text" name="frmAge" size="3" />Years
</p>
<p>
    <label for="text2">Weight:</label>
    <input type="text" name="frmWeight" />in Kg (1st = 6.35kg)
</p>
<p>
    <label for="text3">Serum Creatinine:</label>
    <input type="text" name="frmSerCre" />
    μmol/L
</p>
<p>
    <label for="text4">Gender:</label>
    <select name="frmGender" id="select">
        <option value="M">Male</option>
        <option value="F">Female</option>
    </select>
</p>
<p>
    <input type="submit" value="Calculate" /></p>
</form>
<p>@totalMessage</p>

这篇关于用剃刀(包括小数)的形式计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:24