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.toUint32()\u003c/code\u003e casts a given Earth Engine Number to an unsigned 32-bit integer.\u003c/p\u003e\n"],["\u003cp\u003eThe method handles out-of-range values by clamping them to the minimum (0) or maximum (4294967295) value of a uint32.\u003c/p\u003e\n"],["\u003cp\u003eCasting floating point numbers to uint32 using this method results in loss of decimal precision.\u003c/p\u003e\n"],["\u003cp\u003eThe output of the function is an Earth Engine Number object representing the unsigned 32-bit integer.\u003c/p\u003e\n"]]],[],null,["Casts the input value to an unsigned 32-bit integer.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------|---------|\n| Number.toUint32`()` | Number |\n\n| Argument | Type | Details |\n|---------------|--------|------------------|\n| this: `input` | Number | The input value. |\n\nExamples\n\nCode Editor (JavaScript) \n\n```javascript\n// Cast a number to unsigned 32-bit integer: [0, 4294967295].\nvar number = ee.Number(100);\nprint('Number:', number);\n\nvar uint32Number = number.toUint32();\nprint('Number cast to uint32:', uint32Number);\n\n\n/**\n * Casting numbers to uint32 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 uint32 loses decimal precision.\nvar float = ee.Number(1.7);\nprint('Floating point value:', float);\n\nvar floatToUint32 = float.toUint32();\nprint('Floating point value cast to uint32:', floatToUint32);\n\n// A number greater than uint32 range max cast to uint32 becomes uint32 range max.\nvar UINT32_MAX = 4294967295;\nvar outOfRangeHi = ee.Number(UINT32_MAX + 12345);\nprint('Greater than uint32 max:', outOfRangeHi);\n\nvar outOfRangeHiToUint32 = outOfRangeHi.toUint32();\nprint('Greater than uint32 max cast to uint32 becomes uint32 max:', outOfRangeHiToUint32);\n\n// A number greater than uint32 range min cast to uint32 becomes uint32 range min.\nvar UINT32_MIN = 0;\nvar outOfRangeLo = ee.Number(UINT32_MIN - 12345);\nprint('Less than uint32 min:', outOfRangeLo);\n\nvar outOfRangeLoToUint32 = outOfRangeLo.toUint32();\nprint('Less than uint32 min cast to uint32 becomes uint32 min:', outOfRangeLoToUint32);\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\nColab (Python) \n\n```python\n# Cast a number to unsigned 32-bit integer: [0, 4294967295].\nnumber = ee.Number(100)\nprint('Number:', number.getInfo())\n\nuint32_number = number.toUint32()\nprint('Number cast to uint32:', uint32_number.getInfo())\n\n\n\"\"\"Casting numbers to uint32 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 uint32 loses decimal precision.\nfloat_number = ee.Number(1.7);\nprint('Floating point value:', float_number.getInfo())\n\nfloat_to_uint32 = float_number.toUint32();\nprint('Floating point value cast to uint32:', float_to_uint32.getInfo())\n\n# A number greater than uint32 range max cast to uint32\n# becomes uint32 range max.\nUINT32_MAX = 4294967295\nout_of_range_hi = ee.Number(UINT32_MAX + 12345)\nprint('Greater than uint32 max:', out_of_range_hi.getInfo())\n\nout_of_range_hi_to_uint32 = out_of_range_hi.toUint32()\nprint('Greater than uint32 max cast to uint32 becomes uint32 max:',\n out_of_range_hi_to_uint32.getInfo())\n\n# A number greater than uint32 range min cast to uint32\n# becomes uint32 range min.\nUINT32_MIN = 0\nout_of_range_lo = ee.Number(UINT32_MIN - 12345)\nprint('Less than uint32 min:', out_of_range_lo.getInfo())\n\nout_of_range_lo_to_uint32 = out_of_range_lo.toUint32()\nprint('Less than uint32 min cast to uint32 becomes uint32 min:',\n out_of_range_lo_to_uint32.getInfo())\n```"]]