[[["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.toUint16()\u003c/code\u003e casts a given Earth Engine Number to an unsigned 16-bit integer.\u003c/p\u003e\n"],["\u003cp\u003eThe resulting value will be within the range of 0 to 65535, inclusive.\u003c/p\u003e\n"],["\u003cp\u003eNumbers outside this range will be clamped to the minimum or maximum value.\u003c/p\u003e\n"],["\u003cp\u003eFloating point numbers will lose decimal precision during the conversion.\u003c/p\u003e\n"]]],["The `toUint16()` method casts a number to an unsigned 16-bit integer, with a valid range of 0 to 65535. Input values outside this range are adjusted: values exceeding 65535 become 65535, and those below 0 become 0. Floating-point numbers lose their decimal precision. The method accepts the input number as an argument and returns the cast `Number`. Example code in Javascript and Python, show the casting and boundary behaviors.\n"],null,["# ee.Number.toUint16\n\nCasts the input value to an unsigned 16-bit integer.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------|---------|\n| Number.toUint16`()` | 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 unsigned 16-bit integer: [0, 65535].\nvar number = ee.Number(100);\nprint('Number:', number);\n\nvar uint16Number = number.toUint16();\nprint('Number cast to uint16:', uint16Number);\n\n\n/**\n * Casting numbers to uint16 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 uint16 loses decimal precision.\nvar float = ee.Number(1.7);\nprint('Floating point value:', float);\n\nvar floatToUint16 = float.toUint16();\nprint('Floating point value cast to uint16:', floatToUint16);\n\n// A number greater than uint16 range max cast to uint16 becomes uint16 range max.\nvar UINT16_MAX = 65535;\nvar outOfRangeHi = ee.Number(UINT16_MAX + 12345);\nprint('Greater than uint16 max:', outOfRangeHi);\n\nvar outOfRangeHiToUint16 = outOfRangeHi.toUint16();\nprint('Greater than uint16 max cast to uint16 becomes uint16 max:', outOfRangeHiToUint16);\n\n// A number greater than uint16 range min cast to uint16 becomes uint16 range min.\nvar UINT16_MIN = 0;\nvar outOfRangeLo = ee.Number(UINT16_MIN - 12345);\nprint('Less than uint16 min:', outOfRangeLo);\n\nvar outOfRangeLoToUint16 = outOfRangeLo.toUint16();\nprint('Less than uint16 min cast to uint16 becomes uint16 min:', outOfRangeLoToUint16);\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 unsigned 16-bit integer: [0, 65535].\nnumber = ee.Number(100)\nprint('Number:', number.getInfo())\n\nuint16_number = number.toUint16()\nprint('Number cast to uint16:', uint16_number.getInfo())\n\n\n\"\"\"Casting numbers to uint16 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 uint16 loses decimal precision.\nfloat_number = ee.Number(1.7)\nprint('Floating point value:', float_number.getInfo())\n\nfloat_to_uint16 = float_number.toUint16()\nprint('Floating point value cast to uint16:', float_to_uint16.getInfo())\n\n# A number greater than uint16 range max cast to uint16\n# becomes uint16 range max.\nUINT16_MAX = 65535\nout_of_range_hi = ee.Number(UINT16_MAX + 12345)\nprint('Greater than uint16 max:', out_of_range_hi.getInfo())\n\nout_of_range_hi_to_uint16 = out_of_range_hi.toUint16()\nprint('Greater than uint16 max cast to uint16 becomes uint16 max:',\n out_of_range_hi_to_uint16.getInfo())\n\n# A number greater than uint16 range min cast to uint16\n# becomes uint16 range min.\nUINT16_MIN = 0\nout_of_range_lo = ee.Number(UINT16_MIN - 12345)\nprint('Less than uint16 min:', out_of_range_lo.getInfo())\n\nout_of_range_lo_to_uint16 = out_of_range_lo.toUint16()\nprint('Less than uint16 min cast to uint16 becomes uint16 min:',\n out_of_range_lo_to_uint16.getInfo())\n```"]]