Horje
sprintf add two xeroes for a float number Code Example
sprintf add two xeroes for a float number
$num = 42.0815;

function printFloatWithLeadingZeros($num, $precision = 2, $leadingZeros = 0){
    $decimalSeperator = ".";
    $adjustedLeadingZeros = $leadingZeros + mb_strlen($decimalSeperator) + $precision;
    $pattern = "%0{$adjustedLeadingZeros}{$decimalSeperator}{$precision}f";
    return sprintf($pattern,$num);
}

for($i = 0; $i <= 6; $i++){
    echo "$i max. leading zeros on $num = ".printFloatWithLeadingZeros($num,2,$i)."\n";
}




Cpp

Related
sort sub vector, sort range of vector c++ Code Example sort sub vector, sort range of vector c++ Code Example
how to use printf with <cinttypes> c++ Code Example how to use printf with <cinttypes> c++ Code Example
online c++ graphics compiler Code Example online c++ graphics compiler Code Example
user inptu in cpp Code Example user inptu in cpp Code Example
print set c++ Code Example print set c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9