PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > using explode
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
using explode

Réponse
 
LinkBack Outils de la discussion
Vieux 05/05/2008, 20h04   #1
Jason Pruim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
www.raoset.com
japruim@raoset.com




  Réponse avec citation
Vieux 05/05/2008, 20h12   #2
Zoltán Németh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] using explode

Jason Pruim Ãrta:
> 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?


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

>
> --
>
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424-9337
> www.raoset.com
> japruim@raoset.com
>
>
>
>


  Réponse avec citation
Vieux 05/05/2008, 20h16   #3
Stut
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] using explode

On 5 May 2008, at 20:04, Jason Pruim wrote:
> 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...


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

Untested but should have the same effect as your code.

-Stut

--
http://stut.net/
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08870 seconds with 11 queries