Skip to content

Convert number to Thai Baht as Text, แปลง เลข เป็น บาทไทย, thai baht text javascript

Notifications You must be signed in to change notification settings

paokodo/thai-baht-text-js

 
 

Repository files navigation

Thai Baht Text JS

Installation | Usage

Convert number to Thai Baht as Text

แปลง เลข ให้เป็น หน่วยบาทไทย


Installation

วิธีติดตั้ง

npm install thai-baht-text --save
or
yarn add thai-baht-text

Usage

วิธีการใช้งาน

Javascript ES5

const ThaiBaht = require('thai-baht-text') // for ES5

let money = 10050
let moneyText = ThaiBaht(money)

console.log(moneyText)
// OUTPUT: หนึ่งหมื่นห้าสิบบาทถ้วน

money = 12345678988888.25

console.log(ThaiBaht(money))
// OUTPUT: สิบสองล้านล้านสามแสนสี่หมื่นห้าพ้นหกร้อยเจ็ดสิบแปดล้านเก้าแสนแปดหมื่นแปดพ้นแปดร้อยแปดสิบแปดบาทยี่สิบห้าสตางค์

money = 9007199254740991

ThaiBaht.async(money)
	.then((moneyTextOutput) => {
		console.log(moneyTextOutput)
		// OUTPUT: เก้าพ้นเจ็ดล้านล้านเอ็ดแสนเก้าหมื่นเก้าพ้นสองร้อยห้าสิบสี่ล้านเจ็ดแสนสี่หมื่นเก้าร้อยเก้าสิบเอ็ดบาทถ้วน
	})

More infomation ES5 Example


Javascript ES6

import ThaiBaht from 'thai-baht-text' // for ES6

let money = 10050
let moneyText = ThaiBaht(money)

console.log(moneyText)
// OUTPUT: หนึ่งหมื่นห้าสิบบาทถ้วน

money = 12345678988888.25

console.log(ThaiBaht(money))
// OUTPUT: สิบสองล้านล้านสามแสนสี่หมื่นห้าพ้นหกร้อยเจ็ดสิบแปดล้านเก้าแสนแปดหมื่นแปดพ้นแปดร้อยแปดสิบแปดบาทยี่สิบห้าสตางค์

money = 9007199254740991

ThaiBaht.async(money)
	.then((moneyTextOutput) => {
		console.log(moneyTextOutput)
		// OUTPUT: เก้าพ้นเจ็ดล้านล้านเอ็ดแสนเก้าหมื่นเก้าพ้นสองร้อยห้าสิบสี่ล้านเจ็ดแสนสี่หมื่นเก้าร้อยเก้าสิบเอ็ดบาทถ้วน
	})

More infomation ES6 Example

Suggestion

If your floating point has zero on the lastest, the javascript will remove it automatically. For example

ThaiBaht(131.50)
// OUTPUT หนึ่งร้อยสามสิบเอ็ดบาทห้าสตางค์
// It's wrong!

As you see it would return the wrong result.

So, you just convert it to string, like this.

ThaiBaht('131.50')
// OUTPUT หนึ่งร้อยสามสิบเอ็ดบาทห้าสิบสตางค์
// It's correct! 👏🏻

CAUTION!

You can use number that doesn't over than 9007199254740991

that is MAX_SAFE_INTEGER of javascript.

คุณสามารถใส่เลขได้ไม่เกิน 9007199254740991

ซึ่งเป็น MAX_SAFE_INTEGER ของ javascript


Library & Development Tools

  • Javascript ES6
  • Async
  • Babel

License

The Thai-Baht-Text JS is open-sourced software licensed under the MIT license.

Ending message

If you found bugs or some missing point, please send pull request back or open an issue.

Thank you so much 😃

Regrads,

Jirachai Chansivanon





แปลง เลข เป็น บาทไทย,

thai baht text javascript,

thai baht text js

About

Convert number to Thai Baht as Text, แปลง เลข เป็น บาทไทย, thai baht text javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%