I have two numbers. I want the lower number to be the subtracted from both values.
x: 1000
y: 200
=> result: x = 800 and y = 0.
The following is kinda ugly to me, so is there a better approach I could do this?
if (x <= y) {
y = y - x;
x = 0
} else {
x = x - y;
y = 0;
}
To subtract a number from a range of cells, click on the cell where you want to display the result, and enter “=” (equal) and the cell reference of the first number then “-” (minus) and the number you want to subtract. You can then copy this formula down the column to the rows below.
To subtract whole numbers we write them as in an addition problem and subtract each digit moving from the right to the left. If when subtracting digits, the top number is smaller than the bottom, borrowing becomes necessary. We borrow one from the digit to the left. - 9 We have written 41 as 30 + 11.
This should do it:
int min = Math.min(x, y);
x -= min;
y -= min;
You can do following:
x = x - y;
y = 0;
if(x<0)
{
y = -x
x = 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With