ThaiBahtText
Generate money amount text in Thai language for example: from 121.50 will be "หนึ่งร้อยยี่สิบเอ็ดบาทห้าสิบสตางค์"
Install / Use
/learn @greatfriends/ThaiBahtTextREADME
ThaiBahtText
ให้ข้อความจำนวนเงินภาษาไทย เช่น จำนวน 121.50 บาท จะให้ผลลัพธ์เป็น "หนึ่งร้อยยี่สิบเอ็ดบาทห้าสิบสตางค์"
เริ่มต้นใช้งาน
ภาษา C#
using GreatFriends.ThaiBahtText;
...
decimal amount = 121.50M;
string s = amount.ThaiBahtText(); // หนึ่งร้อยยี่สิบเอ็ดบาทห้าสิบสตางค์
ภาษา Visual Basic .NET
Imports GreatFriends.ThaiBahtText
...
Dim amount As Decimal = 121.50D
Dim s As String = amount.ThaiBahtText() ' หนึ่งร้อยยี่สิบเอ็ดบาทห้าสิบสตางค์
การติดตั้งและอับเดตเวอร์ชั่นล่าสุด
คลิกเมนู TOOLS ใน Visual Studio เลือก NuGet Package Manager > Package Manager Console
PM> Install-Package ThaiBahtText
ตรวจสอบและอับเดตให้เป็นเวอร์ชั่นล่าสุด
PM> Update-Package ThaiBahtText
การถอนการติดตั้งออก
PM> Uninstall-Package ThaiBahtText
Nuget Package Page: https://www.nuget.org/packages/ThaiBahtText/
ตัวเลือก
ฟังก์ชั่น ThaiBahtText มี overloads ดังนี้
- amount.ThaiBahtText(UsesEt mode, Unit unit, int decimalPlaces, bool includeBahtOnly);
- amount.ThaiBahtText(ThaiBahtTextOptions options);
โดยที่ amount อาจจะเป็น decimal หรือ decimal? ก็ได้
คลาส ThaiBahtTextOptions ใช้เพื่อส่งค่าตัวเลือกได้สะดวกขึ้น โดยมี properties ดังนี้
Property | Type |Description
---------| ---------|---------------
UsesEt | enum | การใช้เอ็ดเมื่อมีค่าหนึ่งในหลักหน่วย กำหนดค่าเป็น UsesEt.Always เมื่อต้องการใช้เอ็ดเสมอ (เป็นค่าเริ่มต้น) เช่น ห้าร้อยเอ็ดล้านถ้วน และ UsesEt.TensOnly เมื่อต้องการใช้เอ็ดในหลักสิบเท่านั้น เช่น ห้าร้อยหนึ่งล้านถ้วน
Unit | enum | กำหนดหน่วยของข้อความที่ต้องการว่า จะเป็น Unit.Baht บาท (เป็นค่าเริ่มต้น) Unit.Million ล้านบาท Unit.Billion พันล้านบาท หรือ Unit.Trillion ล้านล้านบาท
DecimalPlaces | int | จำนวนหน่วยทศนิยม มีค่าได้ระหว่าง 0 ถึง 6 (มีค่าเริ่มต้นเป็น 2) จะถูกนำไปใช้ก็ต่อเมื่อ Unit มีค่าไม่เท่ากับ Unit.Baht เท่านั้น
appendBahtOnly | bool | เพิ่มคำว่าถ้วนหรือไม่ (มีค่าเริ่มต้นเป็น true)
UsesEt.Always
ThaiBahtText(UsesEt.Always)
ใช้เอ็ดเสมอ (เป็นค่าเริ่มต้น) สำหรับหลักหน่วยที่มีค่าเป็น 1 รวมถึงหลักล้านที่มีค่าเป็น 1 ด้วย
เป็นรูปแบบที่แนะนำให้ใช้ ตามหลักภาษาไทยที่ถูกต้องแนะนำโดยราชบัณฑิตยสภา
string s21 = (101M).ThaiBahtText(mode: UsesEt.Always); // หนึ่งร้อยเอ็ดบาทถ้วน
string s22 = (101M).ThaiBahtText(); // หนึ่งร้อยเอ็ดบาทถ้วน
string s23 = (11M).ThaiBahtText(); // สิบเอ็ดบาทถ้วน
string s24 = (211M).ThaiBahtText(); // สองร้อยสิบเอ็ดบาทถ้วน
string s25 = (1001M).ThaiBahtText(); // หนึ่งพันเอ็ดบาทถ้วน
string s26 = (1001000000M).ThaiBahtText(); // หนึ่งพันเอ็ดล้านบาทถ้วน
UsesEt.TensOnly
ThaiBahtText(UsesEt.TensOnly)
ใช้เอ็ดเฉพาะกับหลักสิบเท่านั้น (เฉพาะสิบเอ็ดถึงเก้าสิบเอ็ด) ถ้าไม่ระบุจะใช้ตัวเลือกนี้เป็นค่าเริ่มต้น
ไม่เป็นรูปแบบที่แนะนำให้ใช้
string s11 = (101M).ThaiBahtText(mode: UsesEt.TensOnly); // หนึ่งร้อยหนึ่งบาทถ้วน
string s12 = (101M).ThaiBahtText(UsesEt.TensOnly); // หนึ่งร้อยหนึ่งบาทถ้วน
string s13 = (11M).ThaiBahtText(UsesEt.TensOnly); // สิบเอ็ดบาทถ้วน
string s14 = (211M).ThaiBahtText(UsesEt.TensOnly); // สองร้อยสิบเอ็ดบาทถ้วน
string s15 = (1001M).ThaiBahtText(UsesEt.TensOnly); // หนึ่งพันหนึ่งบาทถ้วน
string s16 = (1001000000M).ThaiBahtText(UsesEt.TensOnly); // หนึ่งพันหนึ่งล้านบาทถ้วน
หน่วยของจำนวนเงิน
ค่าเริ่มต้นเป็น บาท แต่สามารถเปลี่ยนข้อความผลลัพธ์เป็นหน่วยอื่นได้ เช่น
var million = new ThaiBahtTextOptions(Unit.Million, appendBahtOnly: false);
var billion = new ThaiBahtTextOptions(Unit.Billion, appendBahtOnly: false);
var s1 = (123456000m).ThaiBahtText(million); // หนึ่งร้อยยี่สิบสามจุดสี่หกล้านบาท
var s2 = (123456000m).ThaiBahtText(billion); // ศูนย์จุดหนึ่งสองพันล้านบาท
ตารางผลลัพธ์
ดูที่ https://github.com/greatfriends/ThaiBahtText/wiki/Sample-Result
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
