Skip to content

Commit

Permalink
v1.1.6
Browse files Browse the repository at this point in the history
* Fix `toBytes()` on float/double/contain dot number to return false.
* Fix zero leading for full number. (change`$num{0}` to just `$num`).
* Fix do not display net for convert Thai Baht.
* Fix dot number to dot number zero, for example: 1.2 to 1.20 before convert Thai Baht.
* Remove zero leading in `convertNumberWithScale()` method.
* Add more tests for via-http and phpunit.
  • Loading branch information
ve3 committed Sep 30, 2018
1 parent 913e8cb commit a851f94
Show file tree
Hide file tree
Showing 16 changed files with 980 additions and 88 deletions.
7 changes: 6 additions & 1 deletion Rundiz/Number/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Number class.
*
* @package Number
* @version 1.1.5
* @version 1.1.6
* @author Vee W.
* @license http://opensource.org/licenses/MIT
*
Expand Down Expand Up @@ -194,6 +194,11 @@ public function toBytes($size)
}
unset($pattern);

if (!isset($matches[2]) && isset($matches[1]) && strpos($matches[1], '.') !== false) {
// if no size unit and the number is float, double, contain dot. cannot convert.
return false;
}

$size_number = 0;
if (isset($matches[1])) {
$size_number = $matches[1];
Expand Down
2 changes: 1 addition & 1 deletion Rundiz/Number/NumberEng.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function convertNumber($num)
$num = ltrim($num, '+');
}

if ($num{0} == '0') {
if ($num == '0') {
$output .= 'zero';
} else {
if (strlen($num) > 36) {
Expand Down
16 changes: 10 additions & 6 deletions Rundiz/Number/NumberThai.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function convertBaht($num, $display_net = true)
$num = ltrim($num, '+');
}

if ($num{0} == '0') {
if ($num == '0') {
$output .= 'ศูนย์';
} else {
$output .= $this->convertNumberWithScale($num);
Expand All @@ -83,16 +83,19 @@ public function convertBaht($num, $display_net = true)
if ($dec > 0) {
// if there is decimal (.)
$dec_str = '';


if (strlen($dec) == 1) {
$dec .= '0';
}
// convert number normally for decimal.
$dec_str = $this->convertNumberWithScale($dec);

if ($dec_str != null) {
$output .= $dec_str . 'สตางค์';
}
}

if (!isset($dec_str) || (isset($dec_str) && $dec_str == null) && $display_net === true) {
if ($display_net === true && (!isset($dec_str) || (isset($dec_str) && $dec_str == null))) {
$output .= 'ถ้วน';
}

Expand Down Expand Up @@ -143,7 +146,7 @@ public function convertNumber($num)
$num = ltrim($num, '+');
}

if ($num{0} == '0') {
if ($num == '0') {
$output .= 'ศูนย์';
} else {
$output .= $this->convertNumberWithScale($num);
Expand All @@ -170,11 +173,12 @@ public function convertNumber($num)
/**
* convert the number to text with scale. (ten, hundred, thousand, ...) in Thai language.
*
* @param number $digits number only. no negative or positive sign. no dot.
* @param string $digits number only. no negative or positive sign. no dot.
* @return string
*/
private function convertNumberWithScale($digits)
{
$digits = ltrim($digits, '0');// remove zero leading. example: 0212, 00213
$length_digit = strlen($digits);
$count = 1;
$pos = 0;// หลักเลข 1=หน่วย, 2=สิบ, 3=ร้อย, ...
Expand Down
Loading

0 comments on commit a851f94

Please sign in to comment.