Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6930747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:29:17+00:00 2026-05-27T11:29:17+00:00

I create a function to compare the price of my item. This is my

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:29:18+00:00Added an answer on May 27, 2026 at 11:29 am

    If it makes sense in your application logic, you can use a Nullable type and use null instead of an empty string. Like :

    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;
            }
    
        }
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created the function of c# to compare the price in my project. public
I want to be able to create a compare function using a class, eg:
I'm trying to create a compare function like the example on the apple site:
Just idly curious why the compare function for stl::sort can't be a static member?
CREATE FUNCTION [dbo].[MSG_FilterAutoship] ( @ItemID VARCHAR(50) = NULL ) RETURNS @Autoship TABLE ( DistID
I can create function pointers in Fortran 90, with code like real, external ::
I already managed to create function which checks if user is using a trial/demo
I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex
I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] (
It is common and easy to create function like: var f = function(){ alert(something);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.