我使用Kentico API在我的網站上顯示我的產品,但我在顯示總購物車價格時遇到問題。它會自動四捨五入 - 如果價格是11.5它使12Kentico中的購物車總價問題
這裏是我的方法返回總價:
public double GetTotalShoppingCart(int userID, string siteName)
{
double totalPrice=0.0;
ShoppingCartInfo cartInfo = GetShopCard(userID, siteName);
int siteID = GetSite(siteName);
if (cartInfo != null)
{
DataSet cartItems = ShoppingCartItemInfoProvider.GetShoppingCartItems(cartInfo.ShoppingCartID);
if (cartItems.Tables[0].Rows.Count > 0)
{
foreach (DataRow row in cartItems.Tables[0].Rows)
{
totalPrice += ShoppingCartItemInfoProvider.GetShoppingCartItemInfo(int.Parse(row["CartItemID"].ToString())).TotalPrice;
}
}
}
return totalPrice;
}
它返回,只有當它是一個整數或實數正確的總價格,但如果它包含任何分數,則將其舍入到最高數字。你知道是什麼導致了這個問題?
當你調試'totalPrice' 11.5或12?如果它是11.5,那麼我不知道你是否可以修改視圖,以便它顯示正確的小數位數可能?另外,是否有你選擇雙精度而不是小數的原因? – KSib