将此数字(例如22.00)转换为2000(不带小数) [英] transform this number (for example 22.00) to 2000 with no decimal

查看:109
本文介绍了将此数字(例如22.00)转换为2000(不带小数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



金额文本框...
该数字为正,该字段应以美分发送($ 22.00应以2200发送,不带小数).
我该怎么办?
在我的第一个表单页面(其中有一个文本框/字段)中
我用

Hi,

Amount text box...
the number is positive and this field should be sent as cents ( $22.00 should be sent as 2200 with no decimal).
How can I ?
in my first form page (where there is a textbox/ field )
I use

private void SetPageState()
        {
         int amountInt = int.Parse(mamountTextBox.Text);
         mFormPageState.AmountContribution = amountInt.ToString("0.00");
        SavePageState();
        }

        public struct FormPageState
        {
        public int amountInt;
        public string AmountContribution;
        }



用户输入例如22
第二个屏幕上,我可以根据需要显示:
22.00使用以下代码



The user enter, for example, 22
and the second screen, I can display as I want:
22.00 with the following code

mAmountLabel.Text = s.AmountContribution;




因此,我必须将此数字(例如22.00)转换为2000,且不带小数以在事务服务器上发送

我怎样才能?您能帮我吗?




So I must transform this number (for example 22.00) to 2000 with no decimal for sending on the transaction server

How can I? could you help me please?

推荐答案

22.00应该以2200的形式发送(不带小数)).
我该怎么办?
在我的第一个表单页面(其中有一个文本框/字段)中
我用

22.00 should be sent as 2200 with no decimal).
How can I ?
in my first form page (where there is a textbox/ field )
I use

private void SetPageState()
        {
         int amountInt = int.Parse(mamountTextBox.Text);
         mFormPageState.AmountContribution = amountInt.ToString("0.00");
        SavePageState();
        }

        public struct FormPageState
        {
        public int amountInt;
        public string AmountContribution;
        }



用户输入例如22
第二个屏幕上,我可以根据需要显示:
22.00使用以下代码



The user enter, for example, 22
and the second screen, I can display as I want:
22.00 with the following code

mAmountLabel.Text = s.AmountContribution;




因此,我必须将此数字(例如22.00)转换为2000,且不带小数以在事务服务器上发送

我怎样才能?您能帮我吗?




So I must transform this number (for example 22.00) to 2000 with no decimal for sending on the transaction server

How can I? could you help me please?


在众所周知这会严重影响财务价值的情况下,我不敢相信这里的答案数量表明建议使用Double变量来获取财务价值.在计算中使用该值时的最终结果.财务值只能以整数或十进制形式(如果后者存在)捕获.
I cannot believe the number of answers here which suggest the use of Double variables to capture a financial value, when it is well known that this can seriously affect the final outcome when such a value is used in calculations. Financial values should only ever be captured as either integer or Decimal (if the latter exists).


尝试类似的方法:

Try something like:

string cost = "22.00";
double doubleVal = 0.0;
if (Double.TryParse(cost, out doubleVal))
{
    int newVal = (int)doubleVal * 100;
    // save this value 

}



[注意:网站前标签格式中的错误迫使我在右大括号前输入多余的一行]



[note: a bug in the site''s pre-tag formatting forces me to enter an extra line before the closing brace]


这篇关于将此数字(例如22.00)转换为2000(不带小数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆