Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have this a record of: 10/2 * 100%
This is equal to 5
How does it save in PHP?
This not work:
($int1/$int2) * 100
Assuming $int1 = 10 and $int2 = 2, you'd have this sum;
echo (10 / 2) * 1; //1 being 100%
Which outputs 5.
http://codepad.org/twp2TduF
There is nothing wrong - it gives your desired result. I assume you were * 100, which would give 500.
Other percentages
* 0.25 = 25%
* 0.75 = 75%
..and so-on
Or refer to this answer
You cannot use percentage this way.
You will need to divide them by 100:
<?php
$int1 = 3;
$int2 = 6;
echo ($int1/$int2) * 100/100;
this above is 100%
and this:
echo ($int1/$int2) * 25/100;
is 25%
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
<?php
$seed = 'COPY_RAFFLE_SEED_HERE'; // Randomly generated seed [Seed:]
$raffle_id = 'COPY_RAFFLE_ID_HERE'; // Raffle ID [Raffle ID:]
$entries = 10; // Number of tickets [Entries count:]
/*
*
* Must +1 return value since it starts with 0
* 28 characters offset to get 4 characters from both hashes
*
*/
$randomNumber = (hexdec(substr(md5($seed) . md5($raffle_id), 28, 8)) % $entries)+1; // Must use +1 as it starts with 0
echo "Ticket with number #$randomNumber won";
apparently this is the code used for the giveaways, and i wanted to see how it works
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
function inchesTodecimal($inches){
return $decimal=inches/12;
}
I want convert inches to decimal like 11=0.917. I want to save 11 inches in database like decimal number 0.917.there is a problem occur when inches is 10.In float type .10=1
First you convert your feet Inches in to feet decimal like 5 feet and after point value convert it into decimal like 11=9.17 then insert into your database. When you want to show on user end you convert again feet Decimal to feet Inches like 5.917=>5.11 its simple hope you got what you want...
Here my simple code for conversion:
function feetInchesToDecimal($feetinches,$precision = 3){
list($feet,$inches) = explode(".",$feetinches);
$inches = preg_replace('/[^0-9.]/','',$inches);
$inches = $inches + ($feet * 12);
return round($inches /12,$precision);
}
function feetDecimalToInchs($feetdecimal){
$feet=(int)$feetdecimal;
$inches=round(($feetdecimal-$feet)*12);
$feetinches=$feet;
if($inches>0) $feetinches.=".".$inches;
return $feetinches;
}
echo feetInchesToDecimal(5.11); //5.917
echo feetDecimalToInchs(5.917); //5.11
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
$VAR= 5;
$VAR1=30;
Mathematical expression :- 5 * 60 * 60 + 30 * 60
i.e. 5 and 30 are $VAR and $VAR1 respectively.
how to use this manually in php code and store result in $RESULT.
This will work:
$result = $VAR * 60 *60 +$VAR1 *60;
The following link will give you an idea of order of preferance
Here is your expression
<?php
$VAR = 5;
$VAR1 = 30;
$calc = - $VAR * 60 * 60 + $VAR1 * 60;
echo $calc;
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a bit of code but it is not echoing the correct answer, or in the correct format. I tried the round function but that didnt show anything
here is my code
$total_per_year = 308790;
$fat = $total_per_year / 3500;
echo $fat;
it is currently showing it as 0.088, but the correct answer is 88.2257142857
how can i do this so it round up to 88.2
The round function requires two parameters like so:
echo round($fat,1);
The second parameter being the amount of decimal places you require.
I have had issues previously with round not working as expected and I had to use number_format:
echo number_format((float)$fat,1,'.','');
With 1 being the decimal places required, the full stop being the decimal separator and '', being the thousand separator.
Use round()
echo round($fat, 1); //second argument is precision eg. decimals
See this for documentation: http://dk1.php.net/round
right, i worked this out now. I know i kept getting '0.088'. And this is wrong.
Its because i had it like this
$total_per_day = number_format($total_per_cup * $number_of_cups);
$total_per_year = number_format($total_per_day * 365);
$fat = round($total_per_year / 3500, 1);
echo $fat;
echo $total_per_year;
this is the correct code.
$total_per_cup = $type_calorie + $milk_calorie + $sugar_calorie;
$total_per_day = $total_per_cup * $number_of_cups;
$total_per_year = $total_per_day * 365;
$fat = $total_per_year / 3500;
echo json_encode(array('total'=> number_format($total_per_year) , 'perday' => number_format($total_per_day), 'fat'=> round($fat, 1)));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I am working on an OSCommerce site, and for the USPS Shipping method I want to convert the weight unit from Pounds to Ounces, but not getting the way how.
Can anyone help?
Given that 1 pound = 16 ounces, you can basically just multiply it by 16:
$pounds = 8;
$ounces = $pounds * 16;
echo $ounces; // 128
...but, if pounds is a float, you will probably want to round it. Since you are talking about shipping weights, you probably want to round up:
$pounds = 8.536;
$ounces = ceil($pounds * 16);
echo $ounces; // 137
You could put this into a function, like this:
function pounds_to_ounces ($pounds) {
return ceil($pounds * 16);
}
echo pounds_to_ounces(8); // 128
echo pounds_to_ounces(8.536); // 137