Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.

Friday, October 19, 2007

ASP .NET - C# Decimal Comparison

A little more shopping cart hacking. Here's how do to Decimal comparisons in C#:


public static decimal GetShippingCost()
{
decimal sum;
decimal shippingCost;
sum = GetSubtotal() - GetCouponDiscount();
if (sum < 0)
sum = 0;

if ( Decimal.Compare(sum, 26.95m) <= 0 )
shippingCost = 8.95m;
else if ( Decimal.Compare(sum, 35.95m) <= 0 )
shippingCost = 11.95m;
else if ( Decimal.Compare(sum, 45.95m) <= 0 )
shippingCost = 12.95m;
else if ( Decimal .Compare(sum, 55.95m) <= 0 )
shippingCost = 16.95m;
else if ( Decimal.Compare(sum, 74.95m) <= 0 )
shippingCost = 18.95m;
else if ( Decimal.Compare(sum, 99.95m) <= 0 )
shippingCost = 20.95m;
else if ( Decimal.Compare(sum, 119.95m) <= 0 )
shippingCost = 22.95m;
else if (Decimal.Compare(sum, 139.95m) <= 0 )
shippingCost = 24.95m;
else if (Decimal.Compare (sum, 159.95m) <= 0 )
shippingCost = 26.95m;
else if (Decimal.Compare(sum, 199.95m) <= 0 )
shippingCost = 29.95m;
else if ( Decimal.Compare(sum, 249.95m ) <= 0 )
shippingCost = 32.95m;
else if (Decimal.Compare(sum, 299.95m) <= 0 )
shippingCost = 34.95m;
else
shippingCost = 34.95m;

return shippingCost;
}

No comments:

About Me

My photo
Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.

Labels