You need to use sprintf or printf to format the output.  Here's the
necessary code:

$Percent = sprintf ("%0.2f", $Percent);

If you use printf it will print the result, whereas sprintf (as used above)
returns the string and lets you assign it to a variable instead.

More info here:  http://www.php.net/manual/function.sprintf.php

-----Original Message-----
From: afan [mailto:[EMAIL PROTECTED]]
Sent: 10 January 2001 19:07
To: [EMAIL PROTECTED]
Subject: decimal numbers


Hi all,
short and simple question:

>From total of 123 elements 79 are ok. What percent?

$Total = 123;
$ok = 78;
$Percent = (100 / 123)  * 78;     //    63.41463414...

But I need just two decimal: 63.41
I'm doing it this way:

$Percent = $Percent * 10;    //    6341.463414...
settype($Percent, "integer");    //    6341
$Percent = $Percent / 10;    //    63.41

I thing there is much better solution!

Thanks for help

Afan

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to