-2

I would like to display the accounting account code using php from 12345678 to form 123.45.678, is there any one can help me ? Thank you

agus priyo
  • 95
  • 1
  • 9
  • 3
    Possible duplicate of [How to format numbers using javascript?](http://stackoverflow.com/questions/5731193/how-to-format-numbers-using-javascript) – Daniel Alder Oct 27 '15 at 08:49
  • Possible duplicate of http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript (How can I format numbers as money in JavaScript?) – Thomas N T Oct 27 '15 at 08:54

2 Answers2

0

you can use a regex for this with preg_replace (for a 8 character digit as in your example) in your php code

$number = 12345678;

echo "Number is: ${number}";
$new_number=preg_replace('/(\d{3})(\d{2})(\d{3})/','$1.$2.$3', $number);

echo "Number is: ${new_number}";
rob
  • 2,136
  • 8
  • 29
  • 37
0

I wrote this up quickly and it seems to provide the functionality you wanted:

https://jsfiddle.net/tdaeunem/

function splitNumber(inputNumber){

    var firstPart = /^(\d{3})/;
    var secondPart = /^\d{3}(\d{2})/;
    var thirdPart = /^\d{5}(\d{3})/;

    var matches = [];

    matches[0] = inputNumber.match(firstPart)[1];

    matches[1] = inputNumber.match(secondPart)[1];

    matches[2] = inputNumber.match(thirdPart)[1];

    return matches.join(".");

}

console.log(splitNumber("12345678"));
OliverRadini
  • 6,238
  • 1
  • 21
  • 46