Is it possible to build a formula that prevents negative numbers?

1.6k Views Asked by At

I have a calculation that goes like this:

$$\text{<any positive number>} - 100$$

As long as the result is a positive number it is acceptable.

However, if the result is a negative number, I need the outcome to calculate to zero. A negative number is not permissible.

Is such a formula possible?


Update 1

This is for use in a CSS calc function .

 .class { margin-top: calc(100vh - 100px); }

I don't want the margin to ever be negative.

The function accepts only basic math operators (+, -, /, *).


Update 2

Some have mentioned in the comments that this question is more about CSS than math, and belongs in Stack Overflow.

However, this question is seeking a mathematical formula which has nothing to do with CSS (or coding, for that matter). It just happens to go into a CSS function.

3

There are 3 best solutions below

3
On BEST ANSWER

You can write the $\max$ as

$\max(x,y) = (|x-y|+x+y)/2$

thus you would like $\max( x-100,0)$ that can be written as $$ (|x-100|+x-100)/2 $$

3
On

It is

$$z=\max(y,0)$$

where $y$ is your number.

1
On

$ y= \begin{cases} x-100 , x>100,\\0 ,0<x\le100 \end{cases} $