OSCommerce USPS convert weight unit from Pound to Ounces [closed] - php

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

Related

idk what this php code does can someone tell me? [closed]

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

How can I save feet and inches in MySQL database? [closed]

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

How to convert the int value to inch in PHP [closed]

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 11 months ago.
Improve this question
I just want to know how to convert inch based on the integer inputted in the field.
For Example:
$int = $_POST['int']; //value 1
//computation here...
$inch = //formula
//echoing the inch
echo $inch;
If you want convert from centimeter can you use this source
function cm2inches($cm)
{
$inches = $cm/2.54;
$inches = $inches%12;
return sprintf('%d ins', $inches);
}
echo cm2inches(162);
You will have result
3 ins

PHP percent calculation not working [closed]

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%

php round up decimals not working [closed]

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)));

Categories