在价格上价值逗号没有被读取 [英] comma on price value is not being read

查看:160
本文介绍了在价格上价值逗号没有被读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其中,它显示了12345,而不是12345。或者有时候我实现了一个价格文本框。 12,345.00。被提交到数据库然而,当,它显示12345逗号不见了。在这个什么花样?这里是我的地方才能按钮code:

i have implemented a price text box wherein it shows 12,345 instead of 12345. Or sometimes. 12,345.00. However when being submitted to the database, it shows 12345. the comma is gone. any tricks on this? here is my place order button code:

 protected void btnPlaceOrder_Click(object sender, EventArgs e)
    {
        string productids = string.Empty;
        DataTable dt;
        if (Session["MyCart"] != null)
        {
            dt = (DataTable)Session["MyCart"];

            decimal totalPrice, totalProducts;
            bool totalPriceConversionResult = decimal.TryParse(txtTotalPrice.Text, out totalPrice), totalProductsConversionResult = decimal.TryParse(txtTotalProducts.Text, out totalProducts);


            ShoppingCart k = new ShoppingCart()
            {
                CustomerName = txtCustomerName.Text,
                CustomerEmailID = txtCustomerEmailID.Text,
                CustomerAddress = txtCustomerAddress.Text,
                CustomerPhoneNo = txtCustomerPhoneNo.Text,
                TotalProducts = totalProductsConversionResult ? Convert.ToInt32(totalProducts) : 0,
                TotalPrice = totalPriceConversionResult ? Convert.ToInt32(totalPrice) : 0,
                ProductList = productids,
                PaymentMethod = rblPaymentMethod.SelectedItem.Text

            };
            DataTable dtResult = k.SaveCustomerDetails();

            for (int i = 0; i < dt.Rows.Count; i++) // loop on how many products are added by the user
            {
                ShoppingCart SaveProducts = new ShoppingCart()
                {
                    CustomerID = Convert.ToInt32(dtResult.Rows[0][0]),
                    ProductID = Convert.ToInt32(dt.Rows[i]["ProductID"]),
                    TotalProducts = Convert.ToInt32(dt.Rows[i]["ProductQuantity"]),
                };
                SaveProducts.SaveCustomerProducts();
            }
            var customerId = Convert.ToInt32(dtResult.Rows[0][0]);
            Response.Redirect(String.Format("OrderSummary.aspx?Id={0}", customerId.ToString()));

什么花招,我可以在总价办?

Any tricks that i can do on the total price?

我试着使用的String.Format尝试,如果它会得到12345,但我失败了。这里是code:

I tried using string.format to try if it will get 12,345 but i failed. here is the code:

lblTotalProducts.Text = Convert.ToString(dtCustomerDetails.Rows[0][String.Format("{0:#,000.00}","TotalProducts")]);

这行code以上将被从数据库中获取数据。

this line of code above will get data from the database.

推荐答案

在数字数据存储,逗号千位分隔符是微不足道的。这只是一个presentation神器。你的情况,让数据库存储的值 12345 ,但使用 12,345.00 >的String.format 方法。请参阅标准数字格式

In numeric data storage, the comma thousand separator is insignificant. It is only a presentation artifact. In your case, let the database store the value as 12345, but display it as 12,345.00 using string.Format method. Please see Standard Numeric Formats.

编辑: lblTotalProducts.Text =的String.Format({0:#,000.00},dtCustomerDetails.Rows [0] [TotalPr oducts]);

这篇关于在价格上价值逗号没有被读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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