php-general | 2001092

RE: [PHP] Fw: Print float with varying format??? From: Maxim Maletsky \(PHPBeginner.com\) (php-general <email protected>)
Date: 09/28/01

Just did a test, and at my surprise a simple round() worked for you.
I thought it was harder than that :-)

<?

$var[] = '1.0000';
$var[] = '1.5000';
$var[] = '1.2500';
$var[] = '1.6667';

for($i=0; $i<sizeof($var); $i++) {
        echo '<br>'.$var[$i] .' becomes ';
        echo round($var[$i], 2);
}

?>

Maxim Maletsky
www.PHPBeginner.com

-----Original Message-----
From: Keith [mailto:kaparsons24 <email protected>]
Sent: venerd́ 28 settembre 2001 14.27
To: php-general <email protected>
Subject: [PHP] Fw: Print float with varying format???

Hello,

I would like to display a float to a precision of 2 but not if the
trailing values are 0.

Ex:
     1.0000 should display '1'
     1.5000 should display '1.5'
     1.2500 should display '1.25'
     1.6667 should display '1.67'

 Is their any display functions that would allow this?
I know that I can display fixed precision of 2 but I don't want the
trailing numbers!

Thanks,
    Keith
     kaparsons24 <email protected>
    Please remove nospam to send mail

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected> To
contact the list administrators, e-mail: php-list-admin <email protected>

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>