When you develop an application or a game in which you have to manage some sort of **score system** it is important to make all **the data simply recognizable**. For example in our new android game FillTheGap is available an Online Ranking in which every player has his own score. To make every score readable we developed this script and today we are going to **explain you how it works!**

#### WHAT IS IT

This simple script allows you to convert a number from this:

To this:

As you can notice the second number looks **much more recognizable**. When you develop an application is crucial to make it as much *simple as possible for your user to understand*. Our script has the purpose to do this for you!

For example, take a look at these two images:

As you can see the scores of the second one are much more easy to visualize than the scores in the first one!

By the way, if you want to download **FillTheGap** you can click on this link below

### HOW DOES IT WORKS

**Get the amount of digits of the number**

You can simply calculate the logarithm to the base 10 of the number itself. Since we need an integer value we have to add 1 to the result and then use the floor function to get the actual digits amount.**'For' cicle on every digit**

To covert the number we need to add an ' every three digits. We can use a 'for' cicle to get every single digits. We introduce two new variables: we use the varaible 'ten' to get the single digits of the whole number; we use the variable 'cont' to know when to add an ' (every three digits).**Get single digits**

To get the every single digit we need to divide the number by the variable 'ten' and then calculate the modulus by 10. Take a look on this example on the number 1234567:**Add the '**

If 'cont' % 3 is equal to 0 we need to add an ' to the number. Otherwise we simply add the digit to the result number.

### THE SCRIPT

We wrote this script in PHP and JAVASCRIPT. As always it is all free and open-source!

```
// Get number from an input field
$number = $_GET['number'];
// Get amount of digits
$cif = floor(log10($number) + 1);
// If number is 0 then return 0
if ($number == 0) {
echo "0";
}
else {
$final = "";
// For cicle to get every single digits and add the '
for ($ten = pow(10, ($cif - 1)), $cont = $cif; $cont > 0; $ten /= 10, --$cont) {
if ($cont % 3 == 0 && $cont != $cif) {
$final .= "'";
}
$single = floor(($number / $ten) % 10);
$final .= $single;
}
// Print the result
echo $final;
}
```

```
// Get number from an input field
var number = document.getElementById('number').value;
// Get amount of digits
var cif = Math.floor(Math.log10(number) + 1);
// If number is 0 then return 0
if (number == 0) {
document.getElementById('numResult').innerHTML = '0';
}
else {
var final = "";
// For cicle to get every single digits and add the '
for (var ten = Math.pow(10, (cif - 1)), cont = cif; cont > 0; ten /= 10, --cont) {
if (cont % 3 == 0 && cont != cif) {
final += "'";
}
var single = Math.floor(((number / ten) % 10));
final += single;
}
// Print the result
document.getElementById('numResult').innerHTML = final;
}
```