How to replace a zero with the number 1, but not in the middle of a number.

Status: Open · Asked by Kari Myers on · 0 views

Kari Myers — Question ·

I'm using Text formatter: replace text to look for a zero and replace it with a 1. But I only want to replace it if the number is actually zero, not in the middle of a number like 205. Is there a way to do this?

Arshil Ahmad — Reply ·

Hi @karilynae,

Please try using this Python code to achieve your use case.

def replace_zero(num):
# Check if the number is exactly 0
if num == 0:
return 1
else:
return num

# Test cases
print(replace_zero(205))

youtube.com/watch?v=iNVjyBfwqno

Stuart Sandweiss — Reply ·

try number formatter > spreadsheet formula
IF("{YOUR_NUM}"="0","1","{YOUR_NUM}")

Kari Myers — Reply ·
Hi @karilynae,

Please try using this Python code to achieve your use case.

def replace_zero(num):
# Check if the number is exactly 0
if num == 0:
return 1
else:
return num

# Test cases
print(replace_zero(205))

youtube.com/watch?v=iNVjyBfwqno


Worked great thanks!
Kari Myers — Reply ·
try number formatter > spreadsheet formula
IF("{YOUR_NUM}"="0","1","{YOUR_NUM}")


Thanks for the response, I already added the python code, but this looks like it would work as well.
Stuart Sandweiss — Reply ·
Thanks for the response, I already added the python code, but this looks like it would work as well.

This way does not cost a task!
Kari Myers — Reply ·
This way does not cost a task!

Great Point! Thanks for the info!

Back to all forum threads · Log in to reply