Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003e\u003ccode\u003eNumber.int16()\u003c/code\u003e casts a given input number to a signed 16-bit integer, within the range of -32768 to 32767.\u003c/p\u003e\n"],["\u003cp\u003eWhen casting a floating-point number, the decimal precision is lost, resulting in the integer part of the number.\u003c/p\u003e\n"],["\u003cp\u003eNumbers exceeding the maximum value of the signed 16-bit integer range are converted to the maximum value (32767).\u003c/p\u003e\n"],["\u003cp\u003eConversely, numbers falling below the minimum value of the signed 16-bit integer range are converted to the minimum value (-32768).\u003c/p\u003e\n"]]],["The `int16()` method casts a number to a signed 16-bit integer, with a range of -32768 to 32767. Input values outside this range are clamped to the range's minimum or maximum. Floating-point numbers lose decimal precision during the cast. The method takes an input `Number` and returns a `Number` of the signed int16 type.\n"],null,["# ee.Number.int16\n\nCasts the input value to a signed 16-bit integer.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|------------------|---------|\n| Number.int16`()` | Number |\n\n| Argument | Type | Details |\n|---------------|--------|------------------|\n| this: `input` | Number | The input value. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Cast a number to signed 16-bit integer: [-32768, 32767].\nvar number = ee.Number(100);\nprint('Number:', number);\n\nvar int16Number = number.int16();\nprint('Number cast to int16:', int16Number);\n\n\n/**\n * Casting numbers to int16 that are outside of its range and precision can\n * modify the resulting value, note the behavior of the following scenarios.\n */\n\n// A floating point number cast to int16 loses decimal precision.\nvar float = ee.Number(1.7);\nprint('Floating point value:', float);\n\nvar floatToInt16 = float.int16();\nprint('Floating point value cast to int16:', floatToInt16);\n\n// A number greater than int16 range max cast to int16 becomes int16 range max.\nvar INT16_MAX = 32767;\nvar outOfRangeHi = ee.Number(INT16_MAX + 12345);\nprint('Greater than int16 max:', outOfRangeHi);\n\nvar outOfRangeHiToInt16 = outOfRangeHi.int16();\nprint('Greater than int16 max cast to int16 becomes int16 max:', outOfRangeHiToInt16);\n\n// A number greater than int16 range min cast to int16 becomes int16 range min.\nvar INT16_MIN = -32768;\nvar outOfRangeLo = ee.Number(INT16_MIN - 12345);\nprint('Less than int16 min:', outOfRangeLo);\n\nvar outOfRangeLoToInt16 = outOfRangeLo.int16();\nprint('Less than int16 min cast to int16 becomes int16 min:', outOfRangeLoToInt16);\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Cast a number to signed 16-bit integer: [-32768, 32767].\nnumber = ee.Number(100)\nprint('Number:', number.getInfo())\n\nint16_number = number.int16()\nprint('Number cast to int16:', int16_number.getInfo())\n\n\n\"\"\"Casting numbers to int16 that are outside of its range and precision can\nmodify the resulting value, note the behavior of the following scenarios.\n\"\"\"\n\n# A floating point number cast to int16 loses decimal precision.\nfloat_number = ee.Number(1.7)\nprint('Floating point value:', float_number.getInfo())\n\nfloat_to_int16 = float_number.int16()\nprint('Floating point value cast to int16:', float_to_int16.getInfo())\n\n# A number greater than int16 range max cast to int16 becomes int16 range max.\nINT16_MAX = 32767\nout_of_range_hi = ee.Number(INT16_MAX + 12345)\nprint('Greater than int16 max:', out_of_range_hi.getInfo())\n\nout_of_range_hi_to_int16 = out_of_range_hi.int16()\nprint('Greater than int16 max cast to int16 becomes int16 max:',\n out_of_range_hi_to_int16.getInfo())\n\n# A number greater than int16 range min cast to int16 becomes int16 range min.\nINT16_MIN = -32768\nout_of_range_lo = ee.Number(INT16_MIN - 12345)\nprint('Less than int16 min:', out_of_range_lo.getInfo())\n\nout_of_range_lo_to_int16 = out_of_range_lo.int16()\nprint('Less than int16 min cast to int16 becomes int16 min:',\n out_of_range_lo_to_int16.getInfo())\n```"]]