Send feedback
ee.Number.int
Stay organized with collections
Save and categorize content based on your preferences.
Casts the input value to a signed 32-bit integer.
Usage Returns Number. int ()
Number
Argument Type Details this: input
Number The input value.
Examples
Code Editor (JavaScript)
// Cast a number to signed 32-bit integer: [-2147483648, 2147483647].
var number = ee . Number ( 100 );
print ( 'Number:' , number );
var intNumber = number . int ();
print ( 'Number cast to int:' , intNumber );
/**
* Casting numbers to int 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 int loses decimal precision.
var float = ee . Number ( 1.7 );
print ( 'Floating point value:' , float );
var floatToInt = float . int ();
print ( 'Floating point value cast to int:' , floatToInt );
// A number greater than int range max cast to int becomes int range max.
var INT_MAX = 2147483647 ;
var outOfRangeHi = ee . Number ( INT_MAX + 12345 );
print ( 'Greater than int max:' , outOfRangeHi );
var outOfRangeHiToInt = outOfRangeHi . int ();
print ( 'Greater than int max cast to int becomes int max:' , outOfRangeHiToInt );
// A number greater than int range min cast to int becomes int range min.
var INT_MIN = - 2147483648 ;
var outOfRangeLo = ee . Number ( INT_MIN - 12345 );
print ( 'Less than int min:' , outOfRangeLo );
var outOfRangeLoToInt = outOfRangeLo . int ();
print ( 'Less than int min cast to int becomes int min:' , outOfRangeLoToInt );
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
# Cast a number to signed 32-bit integer: [-2147483648, 2147483647].
number = ee . Number ( 100 )
print ( 'Number:' , number . getInfo ())
int_number = number . int ()
print ( 'Number cast to int:' , int_number . getInfo ())
"""Casting numbers to int 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 int loses decimal precision.
float_number = ee . Number ( 1.7 )
print ( 'Floating point value:' , float_number . getInfo ())
float_to_int = float_number . int ()
print ( 'Floating point value cast to int:' , float_to_int . getInfo ())
# A number greater than int range max cast to int becomes int range max.
INT_MAX = 2147483647
out_of_range_hi = ee . Number ( INT_MAX + 12345 )
print ( 'Greater than int max:' , out_of_range_hi . getInfo ())
out_of_range_hi_to_int = out_of_range_hi . int ()
print ( 'Greater than int max cast to int becomes int max:' ,
out_of_range_hi_to_int . getInfo ())
# A number greater than int range min cast to int becomes int range min.
INT_MIN = - 2147483648
out_of_range_lo = ee . Number ( INT_MIN - 12345 )
print ( 'Less than int min:' , out_of_range_lo . getInfo ())
out_of_range_lo_to_int = out_of_range_lo . int ()
print ( 'Less than int min cast to int becomes int min:' ,
out_of_range_lo_to_int . getInfo ())
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
Need to tell us more?
[[["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."],[[["The `int()` function casts a given input Number to a signed 32-bit integer within the range of [-2147483648, 2147483647]."],["Casting floating-point numbers using `int()` will result in the loss of decimal precision, truncating the decimal portion."],["If the input number exceeds the maximum value for a signed 32-bit integer, the result will be capped at the maximum value (2147483647)."],["Conversely, if the input number is less than the minimum value for a signed 32-bit integer, the result will be set to the minimum value (-2147483648)."]]],[]]