索引:
一、string.Format()
将【数字字符串】转为两位小数显示的字符串:
1 dt = dtResult.Select(it => new CommodityPriceLimitEntity 2 { 3 CommodityId = it.CommodityId.ToString(), 4 CommodityName = it.CommodityName.ToString(), 5 CommodityCode = it.CommodityCode.ToString(), 6 Price = string.Format("{0:F2}", it.Price) 7 }).ToList();
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
方法一:将时间转为【yyyy/MM/dd HH:mm:ss】 格式显示字符串:
1 if (!string.IsNullOrWhiteSpace(item.EffectiveTimeEnd)) // 生效结束时间 2 { 3 item.EffectiveTimeEnd = string.Format("{0}", item.EffectiveTimeEnd); 4 }
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
方法二:将时间转为【yyyy/MM/dd HH:mm:ss】 格式显示字符串:
1 // 2 mb.CommodityCode = ma.CommodityCode; 3 mb.MaxPrice = ma.MaxPrice.ToString(".00"); 4 mb.MinPrice = ma.MinPrice.ToString(".00"); 5 mb.PriceLimitStart = string.Format(ma.EffectiveTimeStart.ToString(), "yyyy-MM-dd HH:mm:ss"); 6 mb.PriceLimitEnd = string.Format(ma.EffectiveTimeEnd.ToString(), "yyyy-MM-dd HH:mm:ss"); 7 8 // 9 result.Add(mb); 10 } 11 }
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
二、.ToString()
将【数字字符串】转为两位小数显示的字符串:
1 if (dt != null 2 && dt.Count > 0) 3 { 4 foreach (var item in dt) 5 { 6 item.StandardPrice = Convert.ToDecimal(item.StandardPrice).ToString(".00"); 7 item.MinPrice = Convert.ToDecimal(item.MinPrice).ToString(".00"); 8 } 9 }
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
便捷避免【字符串空引用】.ToString()
1 result = result.Select(it => new ChannelCommodityPriceSearchResultDTO 2 { 3 CompanyId = it.CompanyId.ToString(), 4 CompanyName = it.CompanyName.ToString(), 5 CommodityPriceId = it.CommodityPriceId.ToString(), 6 FirstChannelName = it.FirstChannelName.ToString(), 7 SecondChannelID = it.SecondChannelID.ToString(), 8 SecondChannelName = it.SecondChannelName.ToString(), 9 CommodityCode = it.CommodityCode.ToString(), 10 CommodityName = it.CommodityName.ToString(), 11 MainCommodityCode = it.MainCommodityCode.ToString(), 12 GlobalCategoryName = it.GlobalCategoryName.ToString(), 13 MainCategoryName = it.MainCategoryName.ToString(), 14 SubCategoryName = it.SubCategoryName.ToString(), 15 SubCategoryID = (it.SubCategoryID ?? "").ToString(), 16 Price = it.Price.ToString() 17 }).ToList();
------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
持续更新中~~
蒙
2017-08-03 13:58 周四
2017-08-11 04:45 周五 更新于深夜系统发布过程中~~
2017-08-17 09:35 周四