ee.Number.divide

Divides the first value by the second, returning 0 for division by 0.

UsageReturns
Number.divide(right)Number
ArgumentTypeDetails
this: leftNumberThe left-hand value.
rightNumberThe right-hand value.

Examples

Code Editor (JavaScript)

print('5 / 10', ee.Number(5).divide(ee.Number(10)));  // 0.5
print('5 / 10.2', ee.Number(5).divide(ee.Number(10.2)));  // 0.490196078
print('5 / -10.2', ee.Number(5).divide(ee.Number(-10.2)));  // -0.490196078
print('-10.2 / 5', ee.Number(-10.2).divide(ee.Number(5)));  // -2.04
print('-10.2 / -5', ee.Number(-10.2).divide(ee.Number(-5)));  // 2.04
print('0 / 10', ee.Number(0).divide(ee.Number(10)));  // 0
print('10 / 0', ee.Number(10).divide(ee.Number(0)));  // 0

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

import ee
import geemap.core as geemap

Colab (Python)

print('5 / 10:', ee.Number(5).divide(ee.Number(10)).getInfo())  # 0.5
print('5 / 10.2:',
      ee.Number(5).divide(ee.Number(10.2)).getInfo())  # 0.490196078
print('5 / -10.2:',
      ee.Number(5).divide(ee.Number(-10.2)).getInfo()) # -0.490196078
print('-10.2 / 5:', ee.Number(-10.2).divide(ee.Number(5)).getInfo())  # -2.04
print('-10.2 / -5:', ee.Number(-10.2).divide(ee.Number(-5)).getInfo())  # 2.04
print('0 / 10:', ee.Number(0).divide(ee.Number(10)).getInfo())  # 0
print('10 / 0:', ee.Number(10).divide(ee.Number(0)).getInfo())  # 0