Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.
ee.Number.int Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The
int()method casts a number to a signed 32-bit integer within the range of [-2147483648, 2147483647].Casting a floating point number to int loses decimal precision.
Numbers outside the 32-bit integer range are cast to the maximum or minimum value within the range.
| Usage | Returns |
|---|---|
Number.int() | Number |
| Argument | Type | Details |
|---|---|---|
this:input | Number | The input value. |
Examples
Code Editor (JavaScript)
// Cast a number to signed 32-bit integer: [-2147483648, 2147483647].varnumber=ee.Number(100);print('Number:',number);varintNumber=number.int();print('Number cast to int:',intNumber);/** * Casting numbers to int that are outside of its range and precision can * modify the resulting value, note the behavior of the following scenarios. */// A floating point number cast to int loses decimal precision.varfloat=ee.Number(1.7);print('Floating point value:',float);varfloatToInt=float.int();print('Floating point value cast to int:',floatToInt);// A number greater than int range max cast to int becomes int range max.varINT_MAX=2147483647;varoutOfRangeHi=ee.Number(INT_MAX+12345);print('Greater than int max:',outOfRangeHi);varoutOfRangeHiToInt=outOfRangeHi.int();print('Greater than int max cast to int becomes int max:',outOfRangeHiToInt);// A number greater than int range min cast to int becomes int range min.varINT_MIN=-2147483648;varoutOfRangeLo=ee.Number(INT_MIN-12345);print('Less than int min:',outOfRangeLo);varoutOfRangeLoToInt=outOfRangeLo.int();print('Less than int min cast to int becomes int min:',outOfRangeLoToInt);
Python setup
See the Python Environment page for information on the Python API and usinggeemap for interactive development.
importeeimportgeemap.coreasgeemap
Colab (Python)
# Cast a number to signed 32-bit integer: [-2147483648, 2147483647].number=ee.Number(100)display('Number:',number)int_number=number.int()display('Number cast to int:',int_number)"""Casting numbers to int that are outside of its range and precision canmodify the resulting value, note the behavior of the following scenarios."""# A floating point number cast to int loses decimal precision.float_number=ee.Number(1.7)display('Floating point value:',float_number)float_to_int=float_number.int()display('Floating point value cast to int:',float_to_int)# A number greater than int range max cast to int becomes int range max.INT_MAX=2147483647out_of_range_hi=ee.Number(INT_MAX+12345)display('Greater than int max:',out_of_range_hi)out_of_range_hi_to_int=out_of_range_hi.int()display('Greater than int max cast to int becomes int max:',out_of_range_hi_to_int)# A number greater than int range min cast to int becomes int range min.INT_MIN=-2147483648out_of_range_lo=ee.Number(INT_MIN-12345)display('Less than int min:',out_of_range_lo)out_of_range_lo_to_int=out_of_range_lo.int()display('Less than int min cast to int becomes int min:',out_of_range_lo_to_int)
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.