Class: HumanNumber::NumberSystem::EastAsianSystem

Inherits:
DefaultSystem
  • Object
show all
Defined in:
lib/human_number/number_system.rb

Overview

East Asian number formatting system using traditional Asian unit progression.

This system implements the traditional East Asian number formatting convention using powers of 10,000 (万) progression for mid-range numbers, then jumping to 100,000,000 (억/億) and 1,000,000,000,000 (조/兆). This aligns with how numbers are conceptualized and spoken in Korean, Japanese, and Chinese.

The system uses culturally appropriate separators and maintains the original case for Asian characters, unlike the Western system which lowercases full words.

Examples:

Formatting examples

# Korean (만/억/조)
HumanNumber.human_number(12_345, locale: :ko)     #=> "1만 2345"
HumanNumber.human_number(123_456_789, locale: :ko) #=> "1억 2345만 6789"

# Japanese (万/億/兆)
HumanNumber.human_number(12_345, locale: :ja)     #=> "1万 2345"

# Chinese (万/億/兆)
HumanNumber.human_number(12_345, locale: :'zh-CN') #=> "1万 2345"

# Abbreviated mode
HumanNumber.human_number(123_456_789, locale: :ko, max_digits: 2) #=> "1.2억"

Supported locales and currencies

# Locales: [:ko, :ja, :zh, :'zh-CN', :'zh-TW']
# Currencies: ['KRW', 'JPY', 'CNY', 'SGD', 'HKD']

Cultural separators

# Uses locale-specific separators (no space for some Asian languages)
HumanNumber.human_number(12_345_678, locale: :ko) #=> "1234만 5678"

See Also:

Since:

  • 0.1.10

Constant Summary collapse

UNIT_DEFINITIONS =

Since:

  • 0.1.10

[
  { key: :trillion, divisor: 1_000_000_000_000 },
  { key: :hundred_million, divisor: 100_000_000 },
  { key: :ten_thousand, divisor: 10_000 },
].freeze

Class Method Summary collapse

Methods inherited from DefaultSystem

format_below_min_unit, format_in_abbreviated_mode, format_in_complete_mode

Class Method Details

.format_number(number, locale:, abbr_units: true, min_unit: nil, max_digits: 2, trim_zeros: true) ⇒ Object

Since:

  • 0.1.10



565
566
567
568
# File 'lib/human_number/number_system.rb', line 565

def format_number(number, locale:, abbr_units: true, min_unit: nil, max_digits: 2, trim_zeros: true)
  @current_locale = locale.to_sym
  super
end