Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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)."
";
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ operators 
Cpp :: 5 program code in c++ of friend function 
Cpp :: this is my p phone number in punjabi 
Cpp :: deadlock detection in c++coding ninjas 
Cpp :: // A C++ program to show that we can use reference to 
Cpp :: how to find second smallest element using single loop 
Cpp :: inverse elment of array c++ 
Cpp :: multilevel inheritance in c++ private method 
Cpp :: font family slick 
Cpp :: permutation and combination program in c++ 
Cpp :: sort sub vector, sort range of vector c++ 
Cpp :: gcd of two number in c++ stl 
Cpp :: (/~/+|/+$/g, ') 
Cpp :: how to calculate the sum of primary diagonal matrix and secondary diagonal matrix using c++ 
Cpp :: how to call subclass override method in c++ 
Cpp :: Casino Number Guessing Game - C++ 
Cpp :: strip whitespace c++ 
Cpp :: conditions in c++ 
Cpp :: while loop c++ 
Cpp :: how to make an enum in c++ 
Cpp :: c++ delete int 
C :: boilerplate c 
C :: c distance in the cartesian plane 
C :: how to make a hello world program in c 
C :: same project on different monitor in intellij mac 
C :: %hd c 
C :: for loop c 
C :: how to ban websites on mac 
C :: divide and conquer program in c 
C :: connect servo to arduino 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =