คุณสมบัติ

ค่าตัวเลข

การตีความตัวเลขของอักขระ หากมี: ค่าหลัก (0–9) ค่าทศนิยม หรือค่าตัวเลขทั่วไป (เช่น ½ = 0.5, Ⅳ = 4)

· Updated

What Is the Numeric Value Property?

Unicode assigns numeric values to characters that represent numbers across many writing systems. The Numeric_Value property stores the actual number (as a rational), and the companion Numeric_Type property classifies how the character represents a number. This covers far more than the ASCII digits 0–9: Arabic-Indic digits, Roman numerals, circled numbers, vulgar fractions, and Counting Rod numerals all carry numeric values.

Numeric_Type Values

Type Description Examples
Decimal True decimal digit, positional value 0–9 0–9, ٠–٩ (Arabic-Indic), ০–৯ (Bengali)
Digit Digit-like, but not used in positional decimal systems ² ³ (superscript digits)
Numeric Any other numeric character ½ ⅓ Ⅻ 〇
None Not numeric A B !
import unicodedata

chars = [
    ("5",      "ASCII five"),
    ("٥",      "Arabic-Indic five"),
    ("²",      "Superscript two"),
    ("½",      "Vulgar fraction one half"),
    ("Ⅻ",      "Roman numeral 12"),
    ("〇",     "CJK zero"),
    ("A",      "Letter A (not numeric)"),
]

for char, label in chars:
    decimal = unicodedata.decimal(char, None)
    digit   = unicodedata.digit(char, None)
    numeric = unicodedata.numeric(char, None)
    print(f"  {char}  {label}")
    print(f"    decimal={decimal}  digit={digit}  numeric={numeric}")

# 5  decimal=5  digit=5  numeric=5.0
# ٥  decimal=5  digit=5  numeric=5.0
# ²  decimal=None  digit=2  numeric=2.0
# ½  decimal=None  digit=None  numeric=0.5
# Ⅻ decimal=None  digit=None  numeric=12.0
# 〇 decimal=None  digit=None  numeric=0.0
# A  decimal=None  digit=None  numeric=None

The Fraction Challenge

Vulgar fractions like U+2153 (⅓, ONE THIRD) have Numeric_Value = 1/3. Python's unicodedata.numeric() returns the Python float approximation (0.3333...). For exact rational arithmetic you need the stored rational value from the Unicode Character Database directly. The Decimal type is not used here; the float precision is usually sufficient for display but not for precise computation.

Practical Uses

  • Form validation: allow digit characters from any script in numeric fields by checking unicodedata.decimal(c, None) is not None.
  • Sorting numbers expressed in text: normalise digits to ASCII before comparison.
  • OCR post-processing: map non-ASCII digits to their ASCII equivalent using unicodedata.decimal().
  • Accessibility: screen readers use Numeric_Value to pronounce fraction characters correctly.

Quick Facts

Property Value
Unicode property name Numeric_Value, Numeric_Type
Python functions unicodedata.decimal(char[, default]), unicodedata.digit(char[, default]), unicodedata.numeric(char[, default])
Decimal count (Unicode 15.1) ~660 decimal digit characters
Fraction examples ½ (0.5), ⅓ (≈0.333), ⅞ (0.875)
Roman numeral range U+2160–U+217F
Spec reference Unicode Standard Section 4.6

คำศัพท์ที่เกี่ยวข้อง

เพิ่มเติมใน คุณสมบัติ

East Asian Width

Unicode property (UAX#11) classifying characters as Narrow, Wide, Fullwidth, Halfwidth, Ambiguous, or …

Joining Type

Unicode property controlling how Arabic and Syriac characters connect to adjacent characters. …

Script Extensions

Unicode property listing all scripts that use a character, broader than the …

กลุ่มกราฟีม

อักขระที่ผู้ใช้รับรู้ได้ — สิ่งที่รู้สึกเหมือนหน่วยเดียว อาจประกอบด้วยหลายจุดรหัส (ฐาน + เครื่องหมายรวม หรือลำดับ emoji ZWJ) 👩‍💻 = …

การแมปตัวพิมพ์

กฎสำหรับแปลงอักขระระหว่างตัวพิมพ์ใหญ่ ตัวพิมพ์เล็ก และตัวพิมพ์หัวเรื่อง อาจขึ้นอยู่กับ locale (ปัญหาตัว I ในภาษาตุรกี) และอาจเป็นแบบหนึ่ง-ต่อ-หลาย (ß → SS)

การแยกส่วน

การแมปอักขระเป็นส่วนประกอบย่อย การแยกส่วนแบบ canonical รักษาความหมาย (é → e + ́) ในขณะที่การแยกส่วนแบบ compatibility อาจเปลี่ยนความหมาย …

คลาสการรวม

ค่าตัวเลข (0–254) ที่ควบคุมลำดับของเครื่องหมายรวมระหว่างการแยกส่วนแบบ canonical กำหนดว่าเครื่องหมายรวมใดสามารถเรียงลำดับใหม่ได้

ความสมมูลความเข้ากันได้

ลำดับอักขระสองชุดที่มีเนื้อหาเชิงนามธรรมเดียวกันแต่อาจแตกต่างในรูปลักษณ์ กว้างกว่าความเท่าเทียมแบบ canonical ตัวอย่าง: fi ≈ fi, ² ≈ 2

ความสมมูลมาตรฐาน

ลำดับอักขระสองชุดที่มีความหมายเหมือนกันและควรถือว่าเท่าเทียมกัน ตัวอย่าง: é (U+00E9) ≡ e + ◌́ (U+0065 + U+0301)

คุณสมบัติการสะท้อน

อักขระที่รูปร่างควรสะท้อนในแนวนอนในบริบท RTL ตัวอย่าง: ( → ), [ → ], { → }, …