Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Calculation And Limiting Decimals


I have a greater total of 61 and I score 45

$i= 61;
$y= 45;

$pct = ($i /$y) * 100;

one is tha correct Two how can i limit the number that result diplays (0.987654321 - i just want .987)

and how do i turn off this error message???

Warning: Division by zero in localhostinfo.php on line xxx




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Numbers And Decimals
I'm trying to get this 124110 to look like this 124.11 . Here is the code I'm using to get my numbers PHP Code:

Reducing Decimals
Doing a simple division, I obtain this number :
0.002409638554216867234458732127677649259567260742 1875
I'd like to have 0.0024 instead.
I know the number_format function but is it the right solution ?
I thought of another solution :

$MyDec = 0.002409638554216867234458732127677649259567260742 1875;
$MyDecOk = round($MyDec * 10000) / 10000 ; # =0.0024

Is there a special function to do so ?

Random With Decimals
how would i make it so that this script recognizes that the random numbers are with 2 decimal places, and make it so it doesnt just round them up?

$randomattack=rand(.95,1.05);
$randomdefence=rand(.95,1.05);

Format Currency With More Than 2 Decimals
I've tried to use both round and money_format but I can't seem to get what i what.

I have a shopping cart on my web site and I had the tax to the subtotal for calculating the total.

However the following problem arises when using round():
$13.2818
becomes $13.28 (should be $13.29)

$13.2772
becomes $13.28 (works fine)

Is there another function that will ALWAYS round up after X number of decimals?

Formatting Of Decimals In A Table.
I'm not sure how to format :

15.00
155.00

so the .00 part lines up in a cell row I'm using a while loop to display the prices from an array. How do I get them to line up?

Force A Number To Have 2 Decimals
I have a query, and one of the results is a number that I want to forcefully have rounded to 2 decimal places. I couldn't find a good search query to find this if it's been asked before How can I achieve it, so it's like 1.00 or 187.25

Newbie Question (decimals/moneY)
I'm relatively new to PHP, just wondering if there was a quick and easy
way to echo a variable with two decimal places shown even if it is a whole
number. thanks

ex.

$total = 4

needs to echo $total so it shows "4.00"

Displaying Results With Decimals, And Stylizing Them.
I just have what I think is an easy question for some of you. I have a page that pulls all the entries from a specific table in the database. The results are displayed in a table. In this table there is  column for "job_number" this job number is a decimal entry, i need to display the job numbers, grouped by the the numbers ahead of the decimal place and then ordered by the numbers after the decimal. I would also like to indent the decimals ONLY numbers below the under that does not have a decimal. Code:

Limiting Input!
I have recently started a project, and I need to limit user input. I need to make it so the user can only make 1 guess per day. It will collect all the users/guesses for one day, then at the end of the day(12 AM) I will drop all the guesses so they can start guessing again. So I just need to know how to make it so they can only make 1 guess. Code:

Limiting No. Charcters
how to limit the number of charcters when displaying something and having the ending as "..." For example displaying news articles and then a link saying Click Here For More Code:

Limiting Words
I am trying to get a list of news stories from a database and list them, limiting them to a just 100 characters, and rounding them off to the nearest whole sentance, with a Read More » link to read in full. I have written the code, but its not working. Code:

Limiting Search
I have a search result page that is meant to limit the results to 5 per page and then you click next to view the next results (and next for more results and previous for the previous page).

The problem is that when you perform the search it works fine but when you want to go to the next page nothing happens. I think the reason is that it looses the search criteria. Code:

Download Limiting Script
I am looking to make a script for file downloads. Been having a large problem with web-mirroring programs soaking up huge amounts of bandwith.

the script will have to:
1.) accept input for the file's name in this form ?file=blah.zip
2.) take the user to a screen where they can click a post button to begin downloading the file
3.) after clicking that post button and before sending the file, the script will need to make sre that the user is not currently downlaoding any other files, and that the referer was indeed that same script.

this will probably prevent most spiders from sucking the bandwith and driving up the bills, but even if they don't it will slow them sown quite a bit so that the bandwith is managable.

does any one have any ideas on such a script?

PHP, MySQL & Limiting Access
I have a project for work, and I'm not sure how to efficiently do what I
need to do. I'm hoping someone out there can help.

Project is this: I'm creating a web-based interface where people at my
company (operators) can enter data for service calls. All data entered
is run thru one or more PHP scripts for error checking and then stored
in a MySQL database on a server here in the office.

What I'm looking to do is to limit access to certain operators so they
can only do certain functions (ex: add a service call, but not delete
one), whereas admins such as myself would have full access to
everything. Ideally, at some point in the future, we plan to roll this
interface out to our clients so they may do the same features within
their company. Obviously, they would only gain access to data related
to their company, as to protect the privacy of others.

Hierarchy would be something like this:

1. UberAdmins (such as myself)
-Have access to everything and to all commands.

2. Operators
-Have access to everything, but not all commands.

3. Our clients
-Have access to their data only, and to all commands.

4. Our clients' operators
-Have access to their data only, but not all commands.

The difficult thing is that our clients may run several businesses, so
they would have to have access to several groups. In essence, they'd
have multiple groups (their businesses) within a group (their group)
within a group (everything).

What is the easiest and most secure way to do something like this? I'm
not looking for actual code but merely suggestions. Please reply if
there is something I wasn't clear on.

Limiting Simultaneous Logins
What I am trying to do is to limit the number of simultaneous logins of each registered user. Currently each user will be authenticated against a database and a PHP session will be created for him (say $_SESSION['username']). Then we will check for this session in all pages.

Which solution do you recommend to limit the number of simultaneous logins by each user?

Limiting Text Output From DB
I have developed a simple from system that allows users to input some comments. This all works fine, however when I try to retrieve the comments I only want to display 100 characters.

I am new to PHP, but was wondering if there is a string function that will let me take the data from a table in my database and then only display 100 characters followed by "..." afterwards.

Also I have thought of a potential problem... if someone enters less than 100 characters I only want to show the amount they have entered.

Limiting Search Results
I have written a search script for my database but now I want to limit the results to ten a page and then make it possible to see the next (or previous) page. All my attempts so far have failed. Code:

Limiting Charactors Returned.
I'm echoing out table cell kept in an array using: $list['email']
It echos the user's email address. But if i had an email address that was: dwaniodwuaiobwaiubdwauibdvwaijdvwavuwavwad@dwad.com

it would strech the table. I want to limit the amount of charactors. put ...'s inbetween

Limit the output to 10 charactors.

Limiting Character Length
I have a script that pulls latest forum posts with a mysql query.  When I display the list, how do I limit the name of the topics and follow them with "..." if they are too long?  For example, the two latest posts are Hello, everyone, I am new here.  That's sixteen characters.  How would I make that display as say "Hello, Everyone, I am..."

Limiting Access To Upload Area
I'm in the process of creating a Linux+Apache+PHP website with a
public area and an admin area for configuration and updates.

The What:
One of the features of the admin area is image-upload, where the
images are subsequently viewably by the general public. Currently
I've created a dedicated "pictures" directory which world-writable
into which the PHP script puts the form-uploaded images. The admin
logging in is done via a database lookup, not .htaccess directives or
OS permissions.

The How:
It seems a bit risky (is it?) to have to directory so open, is there a
way I can allow the script to move files into that directory without
making it a+w?

Limiting User Mysql Entries
I have a script i'm making which is going to be used to search for reciprocal links on different sites and I have user levels such as free, paid, ect... I want to make it so that if the person signs up as a free user they can only add like 2-3 domains to be searched for their links. How would I limit the number of domains allowed to be searched? Would I limit the number of mysql entries allowed in the table for the domains?

Limiting A Query By Number And Date
I run a hockey league and want to post my schedule for the upcoming season.  The problem is that I have 100 games in the season and I want to limit the query to 30 games on the schedule that is posted on my website.

That part was no problem for me but I also would like to have those 30 games be determined by date. So I would like the script to acquire the current date and post the next 30 games that are upcoming. I have a date field in the daatbase that is in the form YYYY-MM-DD. 

Limiting Number Of Characters In A String...
If I have a long string of text in a variable, how can I "trim" the text down to a specific number of characters?

So for example, if I have:

$string = "This is a string";

and I just want the first four characters of the string, so just "This", how would I do that?

Limiting Characters In Textarea Without Php/javascript
I want to create a textarea in which the user can input 100 characters only.he canot able to input more than 100.i want to do this with out using php/javascript.is it possible.

Date Calculation In PHP
Hi!

I'm trying to get a date with PHP i.e. 14 days from now in yyyy-mm-dd or any other format like print (date("Y-m-d")) + 14 days.

Is there an easy way to do this??

Binary Calculation
I need some way of determining which bits are set in a binary number.

eg.

Decimal Number: 40
Binary Number: 00101000

How can I determine that the binary equivalent of 8 and 32 are set??

Duration Calculation
I had a look at a post here in regards to this issue but after it i was blank. I gave it a shot and i got a wrong value.

Time Calculation With Php
users of my web site enter time and distance of a run the did into a http-form. the data will be processed by a php-script and stored in an mysql-database. what i want to do is to calculate from the data what time they needed for a 1k-run -> i.e.: if one runs 12k in one hour it will be 5 minutes for 1k.

the problem is, the data from the textfield of the form comes in as a string and hence i just can't divide the data ride away.

time input should look like: 1:00:00
distance input should look like: 12
and output should look like: 0:05:00

any ideas?

PHP Math Calculation
I am trying to perform a simple calculation from variables passed from a form. The code is as follows:

<?php
echo "Bonus for the year: <b>";
$x = (($awage * $nibt) + ($awage * $ratio));
$x = number_format($x, 2);
print $x;
echo "</b><p>";
$xtmp = ($x + $qtr);
print $xtmp;?>

The calculation multiplies two different values (based on values from the previous page), and then sets it equal to $x. The first calculation prints fine, but when I try to add it to $qtr (also passed via radio button from previous page), it doesn't calculate correctly.

I found that if I hard-code the values for $x and $qtr after I print $x, then it will calculate correctly. I am thinking that I am using the variables incorrectly somewhere.

Leave Calculation
for example, for the first 2 years, he does not has bonus leave, on the third year onwards, he has 1 day increase. by default, he has 18 days leave, on the third year, he can carry forward the 10 days from the previous year, now, he has 28 days leave plus 1 day bonus leave = 29 days. same with the fourth year, he can carry forward 10 days, so, he has 39 days leave plus 1 day bonus leave = 40 days.

if he apply 2 days leave in the first 2 years, the balance is 16 days. on the third year, he only can carry forward 10 days only, not 16 days. if he apply 12 days leave in the first 2 years, the balance is 6 days. on the third year, he only can carry forward 6 days only, not 10 days. this is the problem that u don't know how to fix, can you teach me?

Time Calculation
does anyone know how to calculate time difference between 2 periods of time(say 12:00 am and 1:00am) ?? i have been trying to come up with an algorithm but bugs keep crawling in.


Date Calculation
I would like to make a selection from the database in the following manner ie which is created in the last 1 week or last 2 weeks. There is one field named created_date in the database and the date is in the format yyyy-mm-dd. I have seen date calculations based on month and year but didn't see one on a week basis.

Date Calculation
I am learning PHP/MySQL, and I am also writting the Library Management
System to make sure that I practice what I am leaning.

My Problem is:

I want to capture the date when the library user borrow the book and then
check that date to see if the book have exceeded the number of days (to
calculate how many days user has stayed with the book once she return it).
Please help me how I can do that. I am using mysql as my database.

Days Calculation
i can't seem to get this what im trying to do is work out the elapsed time in DAYS from 2 dates code is:

             $time_now = time();
             $d2 = date('Y-m-d H:i:s', $time_now);
             $d1 = date('Y-m-d H:i:s', strtotime($ng_date));
             $days = ceil(($d1 - $d2) / (60 * 60 * 24));
when echoing out it produces:

2007-06-02 16:53:24
2007-08-27 18:00:51
which is right, but $days echoes out as 0.

Add Trailing Zero To Calculation
I am pulling a couple of numbers from a database (productcost and productprice).  I am trying to subtract the cost from the price to calculate the profit of the item.  I have this part working with no problem. My problem lies when the final number has a trailing zero it will drop that number (i.e. 1.2 as opposed to 1.20)

Here is what I am using:

$profit = $row_viewcoils['ProductPrice'] - $row_viewcoils['ProductCost'];
      echo $profit;

Calculation Form
I need to build a calculation form.. basically they click a couple radio buttons from features they want and then the user enter's in the number of words of the document and then they hit "calculate" button and it gives them an estimate for a quote. Need a little help with the structure of the form, anyone shed some light?

Limiting Results, And Display Page Numbers
How do I make it so only 50 items display per page. And if there's more than 50, it displays a link "page 2", "page 3" and so on? I know how to limit results with MySQL but how do I generate pages for the next 50 within the PHP code?

Limiting The Amount Of Text From A MySQL Call
I have the following code that pulls some information from a database and presents it (obviously), it also has a link to find out more about the presented information.

One of the feilds is called a biography, I want to limit the amount of the field "biography" that is displayed, like the first 200 characters (maybe even ending in a ...) and have the rest of the biography dislay when the person clicks on the corresponding link. Is this possible? Code:


Limiting The Amount Of Text Returned From A Query
What is the best way to display a limited amount of text returned from a MySql query?

I have a News articles table with a headline and text... I query the database and return both, but I only want to display say the first 30 words of the article text and append it with "... MORE" as a link to the complete article.

The last part is easy, it's the limiting of the number of words displayed that has me stumped.

Alphabetical Sorting... Limiting And Paginating On Next Set Of Letter
I have a query where I am getting one column (designers) in a Table, ordered alphabetically. Right now.. this query is displaying EVERY distinct result (45 in total). This result is used for a subcategory menu on a page. I need to shorten this up considerably. PHP Code:

Limiting Number Of Records Stored In Database
Is there a way I can limit the number of records that are stored in a database? I am using a PHP guestbook script for personal use and only want to save say the last 100 messages.

Limiting/Structuring Query Data Output
Let's say I have a table called "customers" which will display many many results.
What I want to be able to do is output their names in a structured table when a query is presented. For example:

Customer 1, Customer 2, Customer 3, Customer 4
Customer 5, Customer 6, Customer 7, Customer 8

... where it will always revert to the next row after every 4 results, continuing as such.

Limiting Allowed File Format For Upload...
I don't really know much about php and needed to make a web contact form for a client where the user can upload images which are then sent as an attachment with the resulting email.

I kind of cheated and bought a bit of software which creates the script for you. This works great, but I am concerned about people uploading things other than images - especially after seeing this thread:

[URL]....

Now, obviously there is a bit of script in one of the replies which addressed my issue, but I don't know enough about php to adapt it for my own script. Therefore, I was wondering if someone would be so kind as to point out where I need to make changes and what those changes would be.

I need to allow only common image files and to disallow any of the nasty stuff described in the above thread.

I have created this stripped down script with my software, which addresses the essentials of uploaded image and resulting email to which it is attached, plus a section which deals with errors, http referers and stop words for security. The actual script includes more fields, but I thought it would take up too much space!

PHP Code: .....

Leap Year Calculation
how can i incorporate leap year also at my below codes PHP Code:

Create A Function To Do The Calculation
writing the following lines of code into a simple
function. I'd like to be able to create a function to do the
calculation, then feed the $a, $b, or $c variable into it.

<?php $a = $kerryvotes/$votes;
$kpercentage = $a * 100;
$kpercent = round($kpercentage, 0);
?>

<?php $b = $bushvotes/$votes;
$bpercentage = $b * 100;
$bpercent = round($bpercentage, 0);
?>
<?php $c = $nadervotes/$votes;
$npercentage = $c * 100;
$npercent = round($npercentage, 0);
?>

Avg Time On-site Calculation
I am collecting the date and time of each visit to pages on a web-site into a MySQL DB. Would now like to use that info to calculate the avg time a visitor has been on the site.
What is the best way to do that?

Date Comparison Calculation
I want build and extract data from a mysql table by date. The problem is that my table data needs to be by date range as follows.

Example: key field is DATE field
row 1: 02-19-96 to 02-06-97
row 2: 02-07-97 to 01-27-98
row 3: 01-28-98 to 02-15-99

and the input for the query will come from a FORM input (without range), example:
Enter birthday input value could be 05-13-96 How can I query the table and select the row with the correct range.

Relative Link Calculation
I am implementing a semi-template system via the use of 'include()' which pull from files from in a dir in the document root. But as the depth of the files in the direcotry structure changes, you can well imagine that relative links get messued up as the include runs the script from the path from which it was called not the path from which it got the file. So basically I'd just like to know if anyone has a smart script to calculate reltative links.

Date Input And Calculation
I need to input the time into a form for a start time and an end time, and write it to the database. I also need to calculate the time to see the time elasped, and input that into a database, for a field of time spent.


Copyright © 2005-08 www.BigResource.com, All rights reserved