thaibath.

active

Thai Baht currency text conversion and formatting utilities. Converts numbers to Thai Baht words, Thai numerals, and formatted currency strings.

$ cat github.com/arnonsang/thaibath/README.mdsynced 2026-11-19 10:33 ICT · rebuilt daily

npm version npm downloads bundle size license

Thai Baht currency text conversion and formatting utilities. Converts numbers to Thai Baht words, Thai numerals, and formatted currency strings.

Install

npm install thaibath
# or
bun add thaibath
# or
pnpm add thaibath

Usage

import {
  bahtText,
  numberToThaiText,
  satangToText,
  parseBahtText,
  isValidBahtText,
  format,
  formatLong,
  thaiNumerals,
  parseThaiNumerals,
  roundToSatang,
  roundToBaht,
  getBahtSatang,
} from 'thaibath'

bahtText

Convert a number to Thai Baht text, matching Google Sheets BAHTTEXT output.

bahtText(100)        // "หนึ่งร้อยบาทถ้วน"
bahtText(100.50)     // "หนึ่งร้อยบาทห้าสิบสตางค์"
bahtText(11)         // "สิบเอ็ดบาทถ้วน"
bahtText(21)         // "ยี่สิบเอ็ดบาทถ้วน"
bahtText(201)        // "สองร้อยหนึ่งบาทถ้วน"
bahtText(0.5)        // "ห้าสิบสตางค์"
bahtText(-100)       // "ลบหนึ่งร้อยบาทถ้วน"
bahtText(1_234_567)  // "หนึ่งล้านสองแสนสามหมื่นสี่พันห้าร้อยหกสิบเจ็ดบาทถ้วน"
bahtText('1,000')    // "หนึ่งพันบาทถ้วน"

numberToThaiText

Convert a number to Thai words without currency suffix.

numberToThaiText(0)     // "ศูนย์"
numberToThaiText(21)    // "ยี่สิบเอ็ด"
numberToThaiText(100)   // "หนึ่งร้อย"
numberToThaiText(201)   // "สองร้อยหนึ่ง"
numberToThaiText(-10)   // "ลบสิบ"

satangToText

Convert satang (0-99) to Thai text.

satangToText(0)   // "ศูนย์สตางค์"
satangToText(50)  // "ห้าสิบสตางค์"
satangToText(99)  // "เก้าสิบเก้าสตางค์"

parseBahtText

Parse Thai Baht text back to a number. Returns null for invalid input.

parseBahtText('หนึ่งร้อยบาทถ้วน')         // 100
parseBahtText('หนึ่งบาทห้าสิบสตางค์')     // 1.5
parseBahtText('ลบสิบเอ็ดบาทถ้วน')        // -11
parseBahtText('invalid')                // null

isValidBahtText

Check if a string is valid Thai Baht text.

isValidBahtText('หนึ่งร้อยบาทถ้วน')  // true
isValidBahtText('hello')           // false

format

Format a number as Thai Baht currency with optional symbol.

format(1234.56)                     // "฿1,234.56"
format(1234.56, { symbol: false })  // "1,234.56"
format(1234, { decimals: 0 })       // "฿1,234"
format(-1234.56)                    // "฿-1,234.56"

formatLong

Format a number with Thai word labels.

formatLong(1234)                    // "1,234 บาทถ้วน"
formatLong(1234.56)                 // "1,234 บาท 56 สตางค์"
formatLong(1234, { decimals: 2 })   // "1,234 บาท 00 สตางค์"
formatLong(-1234.56)                // "-1,234 บาท 56 สตางค์"

thaiNumerals

Convert Arabic numerals to Thai numerals.

thaiNumerals(123)       // "๑๒๓"
thaiNumerals(1234.56)   // "๑๒๓๔.๕๖"
thaiNumerals(-100)      // "-๑๐๐"
thaiNumerals('1,234')   // "๑,๒๓๔"

parseThaiNumerals

Parse Thai numerals back to a number. Returns null for invalid input.

parseThaiNumerals('๑๒๓')          // 123
parseThaiNumerals('๑,๒๓๔.๕๖')    // 1234.56
parseThaiNumerals('hello')        // null

roundToSatang / roundToBaht

Round a number to satang (2 decimals) or whole baht with configurable mode.

roundToSatang(100.555)           // 100.56
roundToSatang(100.551, 'ceil')   // 100.56
roundToSatang(100.559, 'floor')  // 100.55

roundToBaht(100.5)               // 101
roundToBaht(100.4)               // 100
roundToBaht(100.1, 'ceil')       // 101

getBahtSatang

Split a number into baht and satang components.

getBahtSatang(1234.56)   // { baht: 1234, satang: 56 }
getBahtSatang(0.05)      // { baht: 0, satang: 5 }
getBahtSatang(-1234.56)  // { baht: -1234, satang: 56 }
getBahtSatang('1234.56') // { baht: 1234, satang: 56 }

API Reference

bahtText(num, options?)

Param Type Default Description
num number | string required The amount to convert
options.unit string "บาท" Currency unit word
options.suffix string "ถ้วน" Suffix for whole amounts
options.subUnit string "สตางค์" Sub-unit word for decimals

format(amount, options?)

Param Type Default Description
amount number required The amount to format
options.symbol boolean true Show baht symbol
options.decimals number 2 Decimal places

roundToSatang / roundToBaht

Mode Description
"round" Round half-up (default)
"ceil" Round up
"floor" Round down

Error Handling

Functions throw TypeError for NaN or Infinity inputs. parseBahtText and parseThaiNumerals return null for invalid input. Numbers outside safe integer range throw RangeError.

Grammar

Output matches Google Sheets BAHTTEXT function conventions:

Number Output
11 สิบเอ็ดบาทถ้วน
21 ยี่สิบเอ็ดบาทถ้วน
31 สามสิบเอ็ดบาทถ้วน
101 หนึ่งร้อยหนึ่งบาทถ้วน
201 สองร้อยหนึ่งบาทถ้วน
1001 หนึ่งพันหนึ่งบาทถ้วน
3061 สามพันหกสิบเอ็ดบาทถ้วน
51,000,001 ห้าสิบเอ็ดล้านหนึ่งบาทถ้วน

License

MIT

continue reading on github →