Kotchasan

Currency
in package

Convert numbers to currency format (Baht, Dollar)

Tags
see
https://www.kotchasan.com/

Table of Contents

bahtEng()  : string
Convert number to text (English)
bahtThai()  : string
Convert number to text (Thai Baht)
calcVat()  : float
Calculate the VAT amount based on the given amount and VAT rate.
format()  : string
Format a number with specified decimal digits and thousands separator.
engFormat()  : string
Format a number into its English word representation.

Methods

bahtEng()

Convert number to text (English)

public static bahtEng(string $thb) : string
Parameters
$thb : string
Tags
assert

(13.00) [==] 'thirteen Baht'

assert

(101.55) [==] 'one hundred one Baht and fifty-five Satang'

assert

(1234.56) [==] 'one thousand two hundred thirty-four Baht and fifty-six Satang'

assert

(12345.67) [==] 'twelve thousand three hundred forty-five Baht and sixty-seven Satang'

assert

(-1000000050) [==] 'negative one billion fifty Baht'

assert

(1416921) [==] 'one million four hundred sixteen thousand nine hundred twenty-one Baht'

assert

(269346000.00) [==] 'two hundred sixty-nine million three hundred forty-six thousand Baht'

assert

(1000000000.00) [==] 'one billion Baht'

assert

(10000000050.25) [==] 'ten billion fifty Baht and twenty-five Satang'

assert

(100000000000.00) [==] 'one hundred billion Baht'

assert

(1000000000000) [==] 'one trillion Baht'

assert

(999999999999999) [==] 'nine hundred ninety-nine trillion nine hundred ninety-nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine Baht'

assert

(1000000000000000500) [==] 'one thousand quadrillion five hundred Baht'

Return values
string

bahtThai()

Convert number to text (Thai Baht)

public static bahtThai(string $thb) : string
Parameters
$thb : string
Tags
assert

(13.00) [==] 'สิบสามบาทถ้วน'

assert

(101.55) [==] 'หนึ่งร้อยเอ็ดบาทห้าสิบห้าสตางค์'

assert

(1234.56) [==] 'หนึ่งพันสองร้อยสามสิบสี่บาทห้าสิบหกสตางค์'

assert

(12345.67) [==] 'หนึ่งหมื่นสองพันสามร้อยสี่สิบห้าบาทหกสิบเจ็ดสตางค์'

assert

(-1000000050) [==] 'ลบหนึ่งพันล้านห้าสิบบาทถ้วน'

assert

(1416921) [==] 'หนึ่งล้านสี่แสนหนึ่งหมื่นหกพันเก้าร้อยยี่สิบเอ็ดบาทถ้วน'

assert

(269346000.00) [==] 'สองร้อยหกสิบเก้าล้านสามแสนสี่หมื่นหกพันบาทถ้วน'

assert

(1000000000.00) [==] 'หนึ่งพันล้านบาทถ้วน'

assert

(10000000050.25) [==] 'หนึ่งหมื่นล้านห้าสิบบาทยี่สิบห้าสตางค์'

assert

(100000000000.00) [==] 'หนึ่งแสนล้านบาทถ้วน'

assert

(1000000000000) [==] 'หนึ่งล้านล้านบาทถ้วน'

Return values
string

calcVat()

Calculate the VAT amount based on the given amount and VAT rate.

public static calcVat(float $amount, float $vat[, bool $vat_ex = true ]) : float
Parameters
$amount : float

The amount to calculate VAT for.

$vat : float

The VAT rate.

$vat_ex : bool = true

Indicates whether the amount is VAT-exclusive (true) or VAT-inclusive (false).

Tags
assert

(1000, 7, true) [==] 70

assert

(1000, 7, false) [==] 65.420560747663558

Return values
float

The VAT amount.

format()

Format a number with specified decimal digits and thousands separator.

public static format(float $amount[, int $digit = 2 ][, string $thousands_sep = ',' ][, bool $round = true ]) : string
Parameters
$amount : float

The number to format.

$digit : int = 2

The number of decimal digits to include. Default is 2.

$thousands_sep : string = ','

The character used as a thousands separator. Default is ','.

$round : bool = true

Whether to round the number or not. Default is true.

Tags
assert

(1000000.444) [==] '1,000,000.44'

assert

(1000000.555) [==] '1,000,000.56'

assert

(1000000.55455, 3, ',', false) [==] '1,000,000.554'

assert

(1000000.55455, 3) [==] '1,000,000.555'

Return values
string

The formatted number as a string.

engFormat()

Format a number into its English word representation.

private static engFormat(int $number) : string
Parameters
$number : int

The number to format.

Return values
string

The English word representation of the number.

Search results