ee.Number.format

แปลงตัวเลขเป็นสตริงโดยใช้การจัดรูปแบบสไตล์ printf

การใช้งานการคืนสินค้า
Number.format(pattern)สตริง
อาร์กิวเมนต์ประเภทรายละเอียด
ดังนี้ numberตัวเลขตัวเลขที่จะแปลงเป็นสตริง
patternString, ค่าเริ่มต้น: "%s"สตริงรูปแบบสไตล์ printf เช่น "%.2f" จะสร้างตัวเลขที่จัดรูปแบบเป็น "3.14" และ "%05d" จะสร้างตัวเลขที่จัดรูปแบบเป็น "00042" สตริงรูปแบบต้องเป็นไปตามเกณฑ์ต่อไปนี้
  1. อักขระคำนำหน้า 0 ตัวขึ้นไป
  2. มี "%" 1 ตัว
  3. อักขระตัวแก้ไขตั้งแต่ 0 ตัวขึ้นไปในชุด [#-+ 0,(.\d]
  4. อักขระ Conversion 1 ตัวในชุด [sdoxXeEfgGaA]
  5. อักขระต่อท้าย 0 ตัวขึ้นไป
ดูข้อมูลเพิ่มเติมเกี่ยวกับสตริงรูปแบบได้ที่ 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

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