Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 04-20-2005, 11:26 AM   #1
Varius
Confirmed User
 
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
PHP: How do you convert from EXPONENT_DNUM to LNUM format??

I'm having a very annoying problem this morning....

If I increment a variable by small floats (like 0.00001 lets say) in a loop, the vairable becomes EXPONENT_DNUM format. I would like to keep it in LNUM format. Any ideas?

I've made a simple loop here to show an example:

PHP Code:
<?PHP

$var 
0;

for (
$i=0;$i<5;$i++) {
    
$var += 0.000004;
}

echo 
$var;

?>
That gives me "2E-05" instead of the 0.00002 I"m looking for.
__________________
Skype variuscr - Email varius AT gmail
Varius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-20-2005, 11:31 AM   #2
Varius
Confirmed User
 
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
I do have one way to make it work, but I'd prefer finding out the true method...my way is just a workaround

I replace the last line by this instead, and then it works:

PHP Code:
$num split("-",$var);

echo 
number_format($var,$num[1]); 
__________________
Skype variuscr - Email varius AT gmail
Varius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-20-2005, 11:34 AM   #3
pstation
Confirmed User
 
Join Date: Jul 2003
Location: chicago
Posts: 1,135
use the force
pstation is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-20-2005, 11:36 AM   #4
azguy
Confirmed User
 
Join Date: Nov 2004
Location: Scottsdale, AZ
Posts: 5,167
Try to add 1 to it
azguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-20-2005, 11:39 AM   #5
swedguy
Confirmed User
 
Industry Role:
Join Date: Jan 2002
Posts: 7,981
err......

Last edited by swedguy; 04-20-2005 at 11:40 AM..
swedguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-20-2005, 11:41 AM   #6
Varius
Confirmed User
 
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
Quote:
Originally Posted by azguy
Try to add 1 to it
No luck...also tried * 1, using settype to make sure they are equivalent types and few other things.

The weird part is, if I only add a value once, its fine.

ie.
PHP Code:
$var 0;
$var += 0.00004;

echo 
$var
will give me 0.00004 as output.

Once I loop on it though and add more values, it changes format.

Weird, no one on IRC or google could solve it...my fix above though works for my purposes..
__________________
Skype variuscr - Email varius AT gmail
Varius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-20-2005, 11:42 AM   #7
azguy
Confirmed User
 
Join Date: Nov 2004
Location: Scottsdale, AZ
Posts: 5,167
Quote:
Originally Posted by Varius
No luck...also tried * 1, using settype to make sure they are equivalent types and few other things.

The weird part is, if I only add a value once, its fine.

ie.
PHP Code:
$var 0;
$var += 0.00004;

echo 
$var
will give me 0.00004 as output.

Once I loop on it though and add more values, it changes format.

Weird, no one on IRC or google could solve it...my fix above though works for my purposes..
I'd stick to what works then
azguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-20-2005, 11:43 AM   #8
jeffs
Confirmed User
 
Join Date: Oct 2002
Location: chair
Posts: 135
You can use printf("%f", $var) or printf("%.5f", $var) instead of echo $var.
jeffs is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-20-2005, 12:04 PM   #9
mortenb
Confirmed User
 
mortenb's Avatar
 
Join Date: Jul 2004
Location: Denmark ICQ: 7880009
Posts: 2,203
PHP Code:

<?PHP
bcscale
(6);
$var    0;

for (
$i=0;$i<5;$i++) {
    
$var    bcadd($var,1.000004);
}
$var    bcsub($var,5);

echo 
$var;
?>
dunno if that is close enough for you..
mortenb is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.