percentage droplet

pcwacht

no problem, my fingers are dyslexic too ;)
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....

DarkViper

ok, ok.... for the next time i've cleaned the keyboard of my laptop...   :roll:
[url=http://www.youtube.com/watch?v=tmzDAz6ZvFQ]Der blaue Planet[/url] - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen[br]
[i]"You have to take the men as they are... but you can not leave them like that !" :-P [/i]
[i]Das tägliche Stoßgebet: [b]Oh Herr, wirf Hirn vom Himmel ![/b][/i]

snark

helemaal te gek!

dankjewel

pcwacht

Typo?


<?php

  $basevalue  
= isset($basevalue) ? (float)$basevalue 0;
  if( !
$basevalue ) return '0';  // Division by zero protection
  
$percentvalue = isset($percentvalue) ? (float)$percenvalue 0;
  if( !
$percenvalue ) return '0';
  
$decimals = isset($decimals) ? (intval($decimals) % 11) : 0;

  return  
number_format( (( 100 $percentvalue ) / $basevalue ), $decimals );

?>


<?php

  $basevalue  
= isset($basevalue) ? (float)$basevalue 0;
  if( !
$basevalue ) return '0';  // Division by zero protection
  
$percentvalue = isset($percentvalue) ? (float)$percentvalue 0;
  if( !
$percentvalue ) return '0';
  
$decimals = isset($decimals) ? (intval($decimals) % 11) : 0;

  return  
number_format( (( 100 $percentvalue ) / $basevalue ), $decimals );

?>

twice the missing 't' in percentvalue

Didn't test it...
Have fun,
John
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....

snark

looks great but it returns a "0" as percentage to everything I fill in ...


DarkViper

#2
Droplet:  [percentage]

 [[percentage?basevalue=200&percentvalue=20&decimals=0]]

 20€ of  200€ are 10%

 [[percentage?basevalue=55&percentvalue=5&decimals=4]]

 5€ of 55€ are 9.0909%

The Droplet can handle integer and floatingpoint also
The number of decimals can be between 0 and 10

Code (Droplet percentage) Select
<?php

  $basevalue  
= isset($basevalue) ? (float)$basevalue 0;
  if( !
$basevalue ) return '0';  // Division by zero protection
  
$percentvalue = isset($percentvalue) ? (float)$percentvalue 0;
  if( !
$percentvalue ) return '0';
  
$decimals = isset($decimals) ? (intval($decimals) % 11) : 0;

  return  
number_format( (( 100 $percentvalue ) / $basevalue ), $decimals );

?>


have fun.....
[url=http://www.youtube.com/watch?v=tmzDAz6ZvFQ]Der blaue Planet[/url] - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen[br]
[i]"You have to take the men as they are... but you can not leave them like that !" :-P [/i]
[i]Das tägliche Stoßgebet: [b]Oh Herr, wirf Hirn vom Himmel ![/b][/i]

snark

the following script calculates a percentage:

<?php
function percent($num_amount$num_total) {
$count1 $num_amount $num_total;
$count2 $count1 100;
$count number_format($count20);
echo 
$count;
}
?>



which can be called by:


<?php percent(14412);?>



now I want to use this as a droplet which will app. be something like:
[[percentage?firstnumber=144&secondnumber=12]]

is there anyone who can help me here?