Join 150,407 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 948 people online right now. Registration is fast and FREE... Join Now!
//If statement for commission when greater or equal than quota if (sales >= quota) { commission = comRate * sales; return commission; } //Blank value for commission if less than quota else { return ""; } }
That is the segment to my code.
What I'm trying to do is return a blank text box instead of 0. I've tried converting a double variable to a string, but it says I cannot implicitly do that and I know no other way to do it other than to change the type of function. (Trying to avoid doing that because of the immense size of the program.)
//If statement for commission when greater or equal than quota if (sales >= quota) { commission = comRate * sales; return commission; } //Blank value for commission if less than quota else { return null; } }
Well null is not going to work because it is a value type. You need something to convert to double, but anything of no value is converted to zero because that is what nothing is in a double. 0 means nothing when you are talking doubles. But in terms of your method here, 0 would be fine. You are saying that if they don't meet their quota that they get no commission. Hence they get nothing, nada... ZERO!
//If statement for commission when greater or equal than quota if (sales >= quota) { commission = comRate * sales; return commission; } //Blank value for commission if less than quota else { return 0; } }
Then before putting the value into your TextBox check it's value, if it's 0 don't put anything into the textbox, like so
Well null is not going to work because it is a value type. You need something to convert to double, but anything of no value is converted to zero because that is what nothing is in a double. 0 means nothing when you are talking doubles. But in terms of your method here, 0 would be fine. You are saying that if they don't meet their quota that they get no commission. Hence they get nothing, nada... ZERO!
I'm starting to think that that would be a better idea.
Well null is not going to work because it is a value type. You need something to convert to double, but anything of no value is converted to zero because that is what nothing is in a double. 0 means nothing when you are talking doubles. But in terms of your method here, 0 would be fine. You are saying that if they don't meet their quota that they get no commission. Hence they get nothing, nada... ZERO!
I'm starting to think that that would be a better idea.
Would null work for a void function?
Well what I am saying to you is that for the context you have setup here you want it to return 0. You are saying that they get no commission. Returning null wouldn't be right. I would leave it just the way it is and return 0 indicating they get no commission and do as Psycho suggested, in the calling function check if the commission was zero and blank out the box accordingly.
//Test Box Displays totalBox.Text = totalPay.ToString("N2"); //If statement for commission if value is 0 if (commission == 0) { //Will be blank comBox.Text = ""; } else { //Will have value comBox.Text = commission.ToString("N2"); }
Well, it worked!
I have to say, that the solution to this problem was very easy, yet I did not even think to do it since I was using it in a function.