I’m trying to do some simple math like
$example = (12 - 4);
but I need single digit answers to have a 0 in front of them so $example should be
08 not 8
I know I could do something like
if ($example < 10){
$result = "0$example";
}
But I have to think there’s a way to specify how many digits you want your output to be when doing simple math like this.
I recommend saving formatting like this until you print to screen. You can then use printf or sprintf to format the number how you want.
Will print:
To save it in a string for later use sprintf:
If you need to fill decimal places use the following:
will print: