Skip to content

Instantly share code, notes, and snippets.

@phucdohong96
Last active May 23, 2016 09:49
Show Gist options
  • Select an option

  • Save phucdohong96/7e9020911aea2052e4187e843f5ab320 to your computer and use it in GitHub Desktop.

Select an option

Save phucdohong96/7e9020911aea2052e4187e843f5ab320 to your computer and use it in GitHub Desktop.
Hàm thêm dấu chấm (.) vào một chuỗi số hàng ngàn
<?php
function adddotstring($strNum) {
$len = strlen($strNum);
$counter = 3;
$result = "";
while ($len - $counter >= 0)
{
$con = substr($strNum, $len - $counter , 3);
$result = '.'.$con.$result;
$counter+= 3;
}
$con = substr($strNum, 0 , 3 - ($counter - $len) );
$result = $con.$result;
if(substr($result,0,1)=='.'){
$result=substr($result,1,$len+1);
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment