Skip to content

Commit 1398483

Browse files
Sun-nyLfrancislavoie
authored andcommitted
Added FORMAT to StringFN
1 parent f106748 commit 1398483

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Vectorface/MySQLite/MySQL/StringFn.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,19 @@ public static function mysql_concat_ws()
3535
$str = implode($seperator, $args);
3636
return $str;
3737
}
38+
39+
40+
/**
41+
* Format - Return a formated number string based on the arguements provided
42+
* Ignoring the functionality of a third argument, locale
43+
* https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_format
44+
* @return string $str formatted as per arg
45+
*/
46+
public static function mysql_format()
47+
{
48+
$args = func_get_args();
49+
$number = $args[0];
50+
$decimals = $args[1];
51+
return number_format($number, $decimals);
52+
}
3853
}

tests/Vectorface/Tests/MySQLite/MySQLiteTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,15 @@ public function testRand()
156156
array_slice($results, 10, 10)
157157
);
158158
}
159+
160+
public function testFormat()
161+
{
162+
$expected = '12,312,312';
163+
$test = MySQLite::mysql_format("12312312.232", 0);
164+
$this->assertEquals($expected, $test);
165+
166+
$expected = '12.2';
167+
$test = MySQLite::mysql_format("12.232", 1);
168+
$this->assertEquals($expected, $test);
169+
}
159170
}

0 commit comments

Comments
 (0)