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.format Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The
Number.format()method converts a number to a string using printf-style formatting.The
patternargument is a printf-style format string that specifies how the number should be formatted.Examples demonstrate formatting numbers with zero-filling, specific decimal places, and scientific notation.
| Usage | Returns |
|---|---|
Number.format(pattern) | String |
| Argument | Type | Details |
|---|---|---|
this:number | Number | The number to convert to a string. |
pattern | String, default: "%s" | A printf-style format string. For example, '%.2f' produces numbers formatted like '3.14', and '%05d' produces numbers formatted like '00042'. The format string must satisfy the following criteria:
|
Examples
Code Editor (JavaScript)
print('Zero-fill to length of 3',ee.Number(1).format('%03d'));// 001print('Include 1 decimal place in 1.2347',ee.Number(1.23476).format('%.1f'));// 1.2print('Include 3 decimal places in 1.2347',ee.Number(1.23476).format('%.3f'));// 1.235 (rounds up)print('Scientific notation with 3 decimal places shown',ee.Number(123476).format('%.3e'));// 1.235e+05 (rounds up)print('Integer with 2 decimal places of precision',ee.Number(123476).format('%.2f'));// 123476.00
Python setup
See the Python Environment page for information on the Python API and usinggeemap for interactive development.
importeeimportgeemap.coreasgeemap
Colab (Python)
display('Zero-fill to length of 3:',ee.Number(1).format('%03d'))# 001display('Include 1 decimal place in 1.2347:',ee.Number(1.23476).format('%.1f'))# 1.2display('Include 3 decimal places in 1.2347:',ee.Number(1.23476).format('%.3f'))# 1.235 (rounds up)display('Scientific notation with 3 decimal places shown:',ee.Number(123476).format('%.3e'))# 1.235e+05 (rounds up)display('Integer with 2 decimal places of precision:',ee.Number(123476).format('%.2f'))# 123476.00
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 2024-09-19 UTC.