【问题标题】:Converting a Numeric value fetched from a Dataset to a String Asp.net c#?将从数据集获取的数值转换为字符串 Asp.net c#?
【发布时间】:2013-05-16 07:04:18
【问题描述】:

我的数据库中有这样的数值,

14192555.00

当我得到它并将其放入文本框并将其转换为字符串时,

this.txtPriorNYSDOTRating.Text = ds.Tables[0].Rows[0]["Fact2A_PriorNYSDOTPerfRatingScore"].ToString();
14192555.0000

我也尝试过格式化,

this.txtPriorNYSDOTRating.Text = ds.Tables[0].Rows[0]["Fact2A_PriorNYSDOTPerfRatingScore"].ToString("0.####");

导致错误“no overload for method string

希望您的建议提前谢谢

已编辑:

我在数据库中有日期,例如,

2010-10-19 00:00:00.000

我明白了,

10/19/2010 12:00:00 AM

我的代码是,

this.txtDesignatedDate.Text =Convert.ToDateTime(ds.Tables[0].Rows[0]["DesignatedDate"]).ToString();

如何将其格式化为仅获取 `"10/19/2010"

希望得到您的回复

【问题讨论】:

    标签: c# asp.net formatting decimal


    【解决方案1】:

    您需要将其转换为双精度,然后应用该格式。

    double d = Convert.ToDouble(ds.Tables[0].Rows[0]["Fact2A_PriorNYSDOTPerfRatingScore"]);
    this.txtPriorNYSDOTRating.Text = d.ToString("0.####");
    

    目前它属于object 类型,并且不会使用格式参数公开ToString 重载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多