I have a 'factor' $var which sometimes might be
0.05 or 0.10, etc., but I can't figured out with
number_format or preg_replace how to get either
into $newvar to display as 5% or 10% (or
whatever number the original $var might be.)

Psuedo-Code would be something like:

if ($var has a '0' right after the decimal point (like 0.05), 
nuke the zero to yield only the right hand number(s) 
which followe AND nuke the decimal and anything to 
the left of it.  Then, display it followed by a "%" in text 
like:  5%

$newvar = somealgorithm($var)
$final = "$newvar" . "%";

ELSE

if $var has a 1 - 9 digit right after the decimal point 
(like 0.10), do NOT nuke the '0' as above, but do nuke 
the decimal and anything to the left of it and display 
with a text "%" following.

$newvar = somealgorithm($var)
$final = "$newvar" . "%";

I appreciate any help with this.

    Originally posted by LordShryku

     $newvar = ($var * 100)."%";

    [/B]

    Oh my gosh...why didn't I think of that???

    THANKS MUCH :p

      It's always the easy ones that elude me too. I write some 200 line function before I realize I coulda done it in 3 lines 😃

        Write a Reply...