I create a function to compare the price of my item.
This is my function:
public static decimal ComparePrice(decimal Price, decimal WebsitePrice)
{
decimal ZERO_PRICE = 0.00000M;
if(Price == ZERO_PRICE && WebsitePrice > ZERO_PRICE){
return WebsitePrice;
}else if(Price == ZERO_PRICE && WebsitePrice == ZERO_PRICE){
return "";
}else{
return Price;
}
}
if the both(price and websiteprice) is equal 0.00, then it will return the empty string, I know it is not possible to return the string while the function is set to decimal type, but i have no idea what should I do about that. Anyone can help? Thanks.
If it makes sense in your application logic, you can use a Nullable type and use null instead of an empty string. Like :
Or use Decimal.MinValue as suggested as a flag for invalid. (I like the null better, again, just if this is actually a valid value in your logic).