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




How: Convert Floater To A Whole Number W/out Rounding?


I need to round a floater like:

3.999993 DOWN to 3




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Rounding A Number?
how can I make this value:

$fuel = "19312.92";

end up looking like this:

$fuel = "193";

And if possible, always insert a ZERO in front of the result, so that it ends up looking like this:

$fuel = "0193";

Resulting Number Rounding Up!
how I can get a resulting number to always be rounded up. So if I am dividing a number of columns by two, I want the resulting number to always be rounded up if it returns any remainders. Does anyone know how I can do this. I tried using the ceil () function but with no luck.

Rounding Number Question?
Anyone know a ood way to round a number to nearest .5?

IE: 3.22222 becomes 3.0 or 3.6 becomes 3.5.

Im working on a rating system and need to round the number to the nearest .5 or half.

Convert Number To One With A Comma
How can I convert "2000" to "2,000?"

Convert Number To Time Format
how to convert 3232432432,5 to HH:MM:SS (taking in account if it is possible?)

if (it_is_possible) then
convert
echo
exit;

How To Convert Float Number To Integer?
i have a number : 23.56789

i want the number come out with 24..

Convert String To Integer - Not Starting With A Number
I can't get PHP to convert a string to an integer (or pull the numbers OUT of a string) if it doesn't start with a number, which is an issue.

Basically, i'm trying to pull the integers only out of various model numbers for pieces of equipment our store is selling - examples would be something like S820D or MS1798. I only need the 820 or the 1798 from these strings, but PHP doesn't want to play nice with either:

$product_model = "S820D";
$var = intval($product_model);
or
$var = (int) $product_model;

Rounding
hey, how do u round off a number like instead of having..
48.3333333333 u have like 48 or if u have 48.6666666666 u have 49.

Rounding Up
I've been trying to round up a figure from a shopping feed so that instead of displaying 6.989 it displays 6.99.

Basically I want to round up all the figures in the $Price field from the mysql database.

Rounding?
How can I round a php var up to the nearest whole? Ie:

$foo = 21 / 10;
$out = magicround($foo);
echo $out;
output = "3"
??

If there isn't a easy way to do this, how about just plain rounding? Let the output be 2.
What will mysql do if I try and put 2.1 into a int(11) column? Round it? Round it up, round it down? Give me an error I want to do some deviding and sqrrooting but I can't have decimals!

Rounding Up
I need to round up a number, e.g.

$tot = 24;
$rows = 10;
$npos = (integer)(($tot / $rows) + 0.5);

Here the answer is '2', but i'm after '3'.

How to do?

Question Of Rounding
Is there a function in PHP to round numbers up?

Or would i have to implement an if statement?

Precision Rounding
I'm looking into what I need to do to perform accurate financial calculations in PHP.

I didn't really know the details, but I was vaguely aware that there are precision problems with floating point arithmetic. It was more difficult than I expected to find information about that, but I did end up finding a great article on IBM's website: Decimal Arithmetic FAQ.

So it seems that the BCMath functions in PHP could be used to perform the calculations with the necessary precision, except that there doesn't seem to be any rounding function. There is only a scale argument that truncates the result values at a particular number of decimal places. This seems like a glaring omission. You can't use the PHP built in round function because that will convert its argument to a floating point value, making it pointless to use the BCMath functions in the first place.

PHP doesn't really have adequate rounding functions for monetary values anway, including the money_format string function which doesn't even specify how it performs rounding.

So my question is, do you have to write your own rounding function or did I miss something? I've already started writing my own function, because it seems necessary, which will initially support the three types of rounding described in the IBM article -- half-even (Banker's), half-up, and down.

Rounding Problem
If I use round(1.95583, 2); I would get the perfect result of 1.96 for my
currency. But if I round(1.9) I would just get 1.9. Is there a function or
solution so it would always round with 2 digits for a currency?

Rounding Numbers
I am having trouble getting a script to display 2 decimal places when two numbers are added or multiplied.

I need the script to display 15.70 + 5 as 20.70 not 20.7 and 7.5 * 1.25 to display 9.4 not 9.375

Currency Rounding
I have the following output from a calculation: 211.5

I want to print this to screen as 211.50 (currency), but the round($value,2) doesn't force a rounding... is it possible?

Rounding Down Function
I know the function to round. I was wondering is there anyway to round down?

Because the round function currently rounds (for example)4.5 to 5, whereas i want 4.5 to be 4.
Can this be done?

Or will it just be easier for me to -0.1 from the number first?

Rounding Numbers To The Next Highest 50
I can use the round(), ceiling() and floor() functions to make numbers upto the next whole number (3.6 -> 4 etc.) but how do I round a number to the next highest 50?

e.g.

36.3 -> 50
83.2 -> 100
-26.5 -> -50
-94.0 -> -100

Arithmetic - Rounding Quotients
Is there an operand that will return a rounded quotient?

1 Decimal Place Without Rounding
If I have a float number of say 3.478399 How can I reduce the number to 1 decimal place without rounding?

I've tried it will sprintf, but it rounds the 4 to a 5 which I want to avoid.

$float_number = 3.478399;
$new_float_number = sprintf ("%0.1f",$float_number);

Output returns 3.5 when really I need it to be 3.4

Rounding A Variable To Nearest Integer?
how do i round a variable to the nearest integer? In my combat system, for lower lvl players, (level1 mainly) the damage calculated is going to be very low and in decimals. 3.6, 4.55 etc. how can i round it up to the nearest integer? 3.6 becomes 4. 4.55 becomes 5, etc.

Truncate A Decimal Pointed Figure Without Rounding ...
How can I get -0.162058 to -0.1 rather than rounding to -0.2?

I know I'm being stupid here, but it's really bugging me. The number before
the decimal point could 0 - 999

Replace Hex Number Or Decimal Number In A String ?
String may contain alphanumeric values. What is the bestway to replace a hex number such as 0x122aaa and decimal number such as 5678 with a string "blah" Example: I want to replace below--

wr_thru1 data or mask mismatch!! for addr=0x00000b73a0540 & mdfid:11
with
wr_thru1 data or mask mismatch!! for addr=hexVal & mdfid:decVal

Order Number Or Tracking Number
I need to create some kind of random number within a persons session that can be inserted into a customer id column for their orders, customer, and credit card tables.

Unless their is a better way to link a customers information together between a few tables besides using auto increment. Things could get screwed up for me if I use auto increment, especially if someone submits their information but does not actually place an order.

My question is " How can I create a random order number that can be used within a persons session and will stay the same throughout the whole program for that one person? "

Database Stores Default Number Everytime, But I Havent Set A Default Number??
Im having some problems with my database. Everytime i store a number which is longer than 10 numbers the script or database puts this number into the database: 2147483647. Its does this everytime no mather how i write the numbers and nomather how long the number is, it just needs to be over 10.

I have set any default value in the database and to be sure i havent i tried deleting the table, but same thing happends again???

How To Convert Asp To Php
I have a database system coded in asp using dreamweaver mx. Can I convert the code to php by using dreamweaver mx ? If can, please tell me how.

Currently I'm using PWS on Windows ME with MySQL as a database.

How To Convert ASP To PHP?
Any idea how fastly to convert

How to convert ASP to PHP?

How To Convert BMP To Jpg?
I need help for convert bmp image to jpg file. So anyone can help me to
convert bmp image to jpg image by php's GD library or any ways by php.
Please help me as soon as possible. Or you can help me how to resized
bmp file in different dimession other then its actual.

I need image resize functionality for resize it on the while someone
upload image. So Please help me as soon as possible. Coz I am stuck
over here in my last stage project.

ASP Convert To PHP
I have to convert a program currently built in ASP to work under PHP. The following code is an ASP function. Using PHP could somone show me how to build basically the same function in PHP. Basically I understand I will need a class and objects, but my knowledge of the class and objects is limited, I think if I could see this in a php format I would be able to finish the rest of the project on my own. PHP Code:

HOW TO: Convert A Gif To A Jpg In Php?
I have only used the GD lib a little.
Is there a way to convert a file from a .gif to a .jpeg file?

Convert PHP To CGI?
I am learning PHP and will make my scripts with PHP but my webserver does not support PHP but instead supports CGI. Is there a way to convert a PHP script to CGI without having to know both languages?

Pls Convert
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="edna" && password=="guytoi")
{window.location="viewfood.html"; done==1; }
if (username=="tony" && password=="food") {
window.location="editfood.html"; done=1; }
if (username=="arlene" && password=="manitoulin") {
window.location="viewfood.html"; done=1; }
if (done==0) { window.location="failed.html"; }
}
// End -->
</SCRIPT>
-----------------------------------------------------------------------
Pls tell me how or if i need to convert the above to php. Eventually i
would like to open a file with the usernames/passwords--put data in an
array(s) then valadate them but thats down the road.

Convert Hh:mm PM To Hh:mm:ss
Does anyone know of a function or code that will convert hh:mm PM to hh:mm:ss?

I tried the following but it does not work...

$date = "2007-05-08"
$time = "01:30 PM"

$datetime = date("y:m:d h:i:s", strtotime($date . " " . $time)

This yelds $datetime = "2007-05-08 01:30:00" which the database interprets as 1:30 AM

Convert Smiles
Hello,

I'm working on a forum script and I came across something weird. While working on a func to convert text smilies to images i found that some funcs did this with alot of code while i was able to do it with alittle, hence i've come to the conclusion that my way is probably wrong. Let me know what you all think and if this function should work.

Convert .php Into .html
I have a pre-made php class that converts html into pdf documents. It can also convert php pages into pdf but it converts it before the php page executes. So in the resulting pdf you get all the php code. I was wondering is there a way i can let the php page execute and then let the pdf class convert it?

I know it will be hard to say that without looking at the php class. I was thinking would there be a way to execute the the php page, and have it made into an html page? So this way i can run the php class on the html page.

Convert To &ouml;
i want convert special character like ,, or , or to a "special" character.

this character are from a textfield from the user. i want to safe it in a db, and i want that these character are shown exacly the same indepence if on a mac, windows or in america or europe.

Convert PDF To HTML
I found loads of scripts to convert html and other formats to PDF but is there an easy way to do it vice versa?

Convert Html To Pdf
I'm too new in php. my boss wants me to convert a html page to pdf
form. anyone (here) can give me a tips how to do that?

Convert Date Into Day
I posted a question about session variables and appended variable value to a url and I figured it. Thanks for those who helped.

Now, I have question about converting date into actual name of day. For example, converting 2005-05-12 to thursday. Is there a way to do that?

Convert PHP/HTML To PDF
I need to convert PHP page or HTML page to PDF .
Google , and found some tools as follow ,

1) HTML_toPDF -- i have tried to use , however for our client website
, the PDF aligment is out and the fields are overlapping each other.
2) R&OS --- ok but did not convert html/php to pdf , thus the format
in pdf is different as the html/php format which our clients did not
like it.

Anyone have any ideas about different pdf tools? Have some sample code
is much appreaciated.

Upload 3gp, Mov, Avi, Etc And Convert To Flv
I'm working on a project with my own server (xampp 1.54a with apache,
php and mysql. Safe mode has been turned on. To do the task as in
subject, I browse some video class to see people how to do it. The
simplest method seem to execute external program like ffmpeg in PHP.
I've added the path of ffmpeg.exe in the php.ini already:

safe_mode_exec_dir ="C:Program Filesffmpeg;"

However, it still not works. If I disabled the safe mode. It works. Do
I need to add more directory in the safe_mode_exec_dir?

Beside using external program ffmpeg.exe, is there any other better way?

Convert Htm Pages To Php
At present the client has a site constructed of htm pages. The pages now need to include a php script to be run at a particular point on them.

Do i have to convert all pages from .htm to .php? All htm pages at present are connected to a template. Converting them to php might disable the template connectivity. Is there a way to include the php script on the web pages and maintain template connectivity?

Convert String To An Int
how can i convert a string into an integer? say i have a form that submited 10. i want that converted to integer.

Htmlspecialchars() Won't Convert
I can't get htmlspecialchars() to do it's conversion - eg it won't convert -&- to -& amp;-
Does anyone know what could be happening? Code:

Convert Integers To Hex
Is there a built-in PHP function that lets you convert integers to
hexadecimal values?
For example 255 to FF.

Couldn't find any in the manual.

Convert Text
I have a text like this: "Thuy&#7873;n V Bi&#7875;n"
How to convert it to: "Thuyền V* Biển"

Convert NOW() Into PHP Timestamp
How do I convert a field entered into a Mysql database using NOW() into
a format that can be manipulated with PHP's strftime() function?



Convert Date In Php
is there a way to change the format of a date that is submitted through an html form?
example: I have a form with a date field that accepts a standard U.S. date format of (%m/%d/%Y) but then when this: ($_POST['fdate'], "date") occurs I'd like it to take a date value of (%Y-%m-%d) so that the server will handle it.

How Do I Convert Ip Address To Url ?
how do i convert ip address to url ?


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