What is the best way to convert negative values to 0?
Status: Open · Asked by Niche Web Marketing on · 0 views
I have a number formatter math operation that subtracts two numbers and sometimes the values end up being negative. I would like to add another step that will convert any negative values to 0, but if the values are above 0, they stay the same.
What is the best way for me to accomplish this?
You can try adding this Python code to your workflow to achieve this use case.
https://connect.pabbly.com/workflow/share/D0dZawBXUzBVHwJoAFNXcA0ZBgIBWAJjUksDEVJdAHhWDFE6VBUNZ1sXBSdVFgFgB04IYlUKVDAAFAMHVAJUJwEYBxUDAFMpVRgGfVcGDj0PUVlxAGE#
def replace_negative_with_zero(numbers):
result = []
for num in numbers:
if num < 0:
result.append(0)
else:
result.append(num)
return result
# Test the function
numbers = [-9]
result = replace_negative_with_zero(numbers)
print("Numbers after replacement:", result)