function to use instead of sprintf in php code example
Example 1: sprintf
char myConcatenation[80];
char myCharArray[16]="A variable name";
int myInt=5;
sprintf(myConcatenation,"%s = %i",myCharArray,myInt);
Serial.println(myConcatenation);
Example 2: php sprintf
There are already some comments on using sprintf to force leading leading zeros but the examples only include integers. I needed leading zeros on floating point numbers and was surprised that it didn't work as expected.
Example:
<?php
sprintf('%02d', 1);
?>
This will result in 01. However, trying the same for a float with precision doesn't work:
<?php
sprintf('%02.2f', 1);
?>
Yields 1.00.
This threw me a little off. To get the desired result, one needs to add the precision (2) and the length of the decimal seperator "." (1). So the correct pattern would be
<?php
sprintf('%05.2f', 1);
?>
Output: 01.00
Please see http: