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.int8 Stay organized with collections Save and categorize content based on your preferences.
Page Summary
Number.int8()casts a number to a signed 8-bit integer with a range of [-128, 127].Casting floating-point numbers to int8 results in the loss of decimal precision.
Numbers outside the int8 range [-128, 127] will be clamped to the nearest boundary value when cast to int8.
| Usage | Returns |
|---|---|
Number.int8() | Number |
| Argument | Type | Details |
|---|---|---|
this:input | Number | The input value. |
Examples
Code Editor (JavaScript)
// Cast a number to signed 8-bit integer: [-128, 127].varnumber=ee.Number(100);print('Number:',number);varint8Number=number.int8();print('Number cast to int8:',int8Number);/** * Casting numbers to int8 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 int8 loses decimal precision.varfloat=ee.Number(1.7);print('Floating point value:',float);varfloatToInt8=float.int8();print('Floating point value cast to int8:',floatToInt8);// A number greater than int8 range max cast to int8 becomes int8 range max.varINT8_MAX=127;varoutOfRangeHi=ee.Number(INT8_MAX+12345);print('Greater than int8 max:',outOfRangeHi);varoutOfRangeHiToInt8=outOfRangeHi.int8();print('Greater than int8 max cast to int8 becomes int8 max:',outOfRangeHiToInt8);// A number greater than int8 range min cast to int8 becomes int8 range min.varINT8_MIN=-128;varoutOfRangeLo=ee.Number(INT8_MIN-12345);print('Less than int8 min:',outOfRangeLo);varoutOfRangeLoToInt8=outOfRangeLo.int8();print('Less than int8 min cast to int8 becomes int8 min:',outOfRangeLoToInt8);
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 8-bit integer: [-128, 127].number=ee.Number(100)display('Number:',number)int8_number=number.int8()display('Number cast to int8:',int8_number)"""Casting numbers to int8 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 int8 loses decimal precision.float_number=ee.Number(1.7)display('Floating point value:',float_number)float_to_int8=float_number.int8()display('Floating point value cast to int8:',float_to_int8)# A number greater than int8 range max cast to int8 becomes int8 range max.INT8_MAX=127out_of_range_hi=ee.Number(INT8_MAX+12345)display('Greater than int8 max:',out_of_range_hi)out_of_range_hi_to_int8=out_of_range_hi.int8()display('Greater than int8 max cast to int8 becomes int8 max:',out_of_range_hi_to_int8)# A number greater than int8 range min cast to int8 becomes int8 range min.INT8_MIN=-128out_of_range_lo=ee.Number(INT8_MIN-12345)display('Less than int8 min:',out_of_range_lo)out_of_range_lo_to_int8=out_of_range_lo.int8()display('Less than int8 min cast to int8 becomes int8 min:',out_of_range_lo_to_int8)
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.