My problem is actually I want to round-off the Price of an item calculated after applying discount to two decimal places and use this round-off value to calculate further values like total price etc.
To give a background why I am doing is because of some minor miscalculations happening. For e.g. let's say the price of an item is 91.3 and discount applied is like 0.425 the value becomes 91.3 * .425 = $41.3525.
This value is formatted to round-off to two decimal places on the UI side as 41.35. But the actual object for the price in the code is still 41.3525. Now if the user orders 3 items the total price should have been 41.35* 3= 124.05 but as the total price is fetched from the object present in the code this comes out to be 41.3525 * 3= 124.0575 which after round-off is displayed on UI side as 124.06.
So I tried changing the price object by overriding the ShoppingCartInfoProvider class and overriding method EvaluateContentInternal as below:
protected override void EvaluateContentInternal(ShoppingCartInfo cart)
{
base.EvaluateContentInternal(cart);
foreach (DataRow data in cart.ContentTable.Rows)
{
data.SetField("UnitPrice", (Math.Round(Convert.ToDouble(data["UnitPrice"]),2)));
}
cart.ContentTable.AcceptChanges();
}
When I applied debugger to the UnitPrice the value get rounded to two decimal places but I expected other values to be changed by this like the cart.TotalPrice in the cart object but this is still the old value.
Let me know if something more is needed to understand the problem.
Kind Regards,
Amit