Home > DeveloperSection > Forums > Return empty string in decimal function
Ashish Pandey

Total Post:128

Points:898
Posted on    August-25-2014 1:17 AM

 C# C# 
Ratings:


 1 Reply(s)
 682  View(s)
Rate this:

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.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-25-2014 2:17 AM

Hi Ashish, 
try this:

public static decimal? ComparePrice(decimal Price, decimal WebsitePrice)

    {

        if(Price == decimal.Zero && WebsitePrice > decimal.Zero){

            return WebsitePrice;

        }else if(Price == decimal.Zero && WebsitePrice == decimal.Zero){

            return null;

        }else{

            return Price;

        }

    }


Don't want to miss updates? Please click the below button!

Follow MindStick