ee.Number.format

Convert a number to a string using printf-style formatting.

שימושהחזרות
Number.format(pattern)מחרוזת
ארגומנטסוגפרטים
זה: numberמספרהמספר שרוצים להמיר למחרוזת.
patternמחרוזת, ברירת מחדל: ‎"%s"‎מחרוזת פורמט בסגנון printf. לדוגמה, '‎%.2f' יוצר מספרים בפורמט '3.14', ו-'‎%05d' יוצר מספרים בפורמט '00042'. מחרוזת הפורמט צריכה לעמוד בקריטריונים הבאים:
  1. אפס תווים או יותר של התחילית.
  2. סימן '%' אחד בדיוק.
  3. אפס או יותר תווים של משנה בקבוצה [‎#-+ 0,(.\d].
  4. תו המרה אחד בדיוק בקבוצה [sdoxXeEfgGaA].
  5. אפס תווים או יותר של סיומת.
מידע נוסף על מחרוזות פורמט זמין בכתובת https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Formatter.html

דוגמאות

עורך הקוד (JavaScript)

print('Zero-fill to length of 3',
      ee.Number(1).format('%03d'));  // 001

print('Include 1 decimal place in 1.2347',
      ee.Number(1.23476).format('%.1f'));  // 1.2

print('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

מידע על Python API ועל שימוש ב-geemap לפיתוח אינטראקטיבי מופיע בדף Python Environment.

import ee
import geemap.core as geemap

Colab (Python)

print('Zero-fill to length of 3:',
      ee.Number(1).format('%03d').getInfo())  # 001

print('Include 1 decimal place in 1.2347:',
      ee.Number(1.23476).format('%.1f').getInfo())  # 1.2

print('Include 3 decimal places in 1.2347:',
      ee.Number(1.23476).format('%.3f').getInfo())  # 1.235 (rounds up)

print('Scientific notation with 3 decimal places shown:',
      ee.Number(123476).format('%.3e').getInfo())  # 1.235e+05 (rounds up)

print('Integer with 2 decimal places of precision:',
      ee.Number(123476).format('%.2f').getInfo())  # 123476.00