Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > using explode
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 20th April 20:47
japruim
External User
 
Posts: 1
Default using explode



Hi everyone,

I am wondering if I can write this cleaner?
$weightExplode = explode(".", $totalWeight);
$explodetest = ".";
$explodetest .= $weightExplode[1];
$explodetest = $explodetest*16;


I'm hoping I've missed something... Basically I just need to include
the "." in $weightExplode[1] before I multiply it by 16. That's the
only part that is confusing me right now...

Any ideas?

--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
http://www.raoset.com
japruim@raoset.com
  Reply With Quote


  sponsored links


2 20th April 20:47
znemeth
External User
 
Posts: 1
Default using explode



Jason Pruim Ã*rta:

I can't write it cleaner, though I can write it shorter:

$weightExplode = explode('.', $totalWeight);
$explodetest = ((float)('.' . $weightExplode[1])) * 16;

(the (float) casting is maybe not required, but I think it's good practice)

greets,
Zoltán Németh
  Reply With Quote
3 20th April 20:47
stuttle
External User
 
Posts: 1
Default using explode


$explodetest = ($totalWeight - intval($totalWeight)) * 16;

Untested but should have the same effect as your code.

-Stut

--
http://stut.net/
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666