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.toInt64

  • Number.toInt64() casts the input value to a signed 64-bit integer.

  • Casting floating-point numbers to int64 results in the loss of decimal precision.

  • Numbers outside the int64 range when cast become the respective int64 range maximum or minimum.

Casts the input value to a signed 64-bit integer.

UsageReturns
Number.toInt64()Number
ArgumentTypeDetails
this:inputNumberThe input value.

Examples

Code Editor (JavaScript)

// Cast a number to signed 64-bit integer: [-9223372036854776000, 9223372036854776000].varnumber=ee.Number(100);print('Number:',number);varint64Number=number.toInt64();print('Number cast to int64:',int64Number);/** * Casting numbers to int64 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 int64 loses decimal precision.varfloat=ee.Number(1.7);print('Floating point value:',float);varfloatToInt64=float.toInt64();print('Floating point value cast to int64:',floatToInt64);// A number greater than int64 range max cast to int64 becomes int64 range max.varINT64_MAX=9223372036854776000;varoutOfRangeHi=ee.Number(INT64_MAX+12345);print('Greater than int64 max:',outOfRangeHi);varoutOfRangeHiToInt64=outOfRangeHi.toInt64();print('Greater than int64 max cast to int64 becomes int64 max:',outOfRangeHiToInt64);// A number greater than int64 range min cast to int64 becomes int64 range min.varINT64_MIN=-9223372036854776000;varoutOfRangeLo=ee.Number(INT64_MIN-12345);print('Less than int64 min:',outOfRangeLo);varoutOfRangeLoToInt64=outOfRangeLo.toInt64();print('Less than int64 min cast to int64 becomes int64 min:',outOfRangeLoToInt64);

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 64-bit integer:# [-9223372036854775808, 9223372036854775808].number=ee.Number(100)display('Number:',number)int64_number=number.toInt64()display('Number cast to int64:',int64_number)"""Casting numbers to int64 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 int64 loses decimal precision.float_number=ee.Number(1.7)display('Floating point value:',float_number)float_to_int64=float_number.toInt64()display('Floating point value cast to int64:',float_to_int64)# A number greater than int64 range max becomes int64 range max.# Python int is too large to be mapped to int64, use float instead.INT64_MAX=9223372036854775808.0out_of_range_hi=ee.Number(INT64_MAX+12345)display('Greater than int64 max:','{:.0f}'.format(out_of_range_hi.getInfo()))out_of_range_hi_to_int64=out_of_range_hi.toInt64()display('Greater than int64 max cast to int64 becomes int64 max:','{:.0f}'.format(out_of_range_hi_to_int64.getInfo()))# A number greater than int64 range min becomes int64 range min.# Python int is too large to be mapped to int64, use float instead.INT64_MIN=-9223372036854775808.0out_of_range_lo=ee.Number(INT64_MIN-12345)display('Less than int64 min:','{:.0f}'.format(out_of_range_lo.getInfo()))out_of_range_lo_to_int64=out_of_range_lo.toInt64()display('Less than int64 min cast to int64 becomes int64 min:','{:.0f}'.format(out_of_range_lo_to_int64.getInfo()))

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.