Re: round up to float 0.00

From: Date: Tue, 27 Jun 2000 18:44:12 +0000
Subject: Re: round up to float 0.00
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-3396@lists.php.net to get a copy of this message
sprintf() will do it, but you have to use the printf() format specifiers. In your case, your statement would be $num1 = sprintf ("%.2f", $num2); where $num2 is the number you're rounding and $num1 is the string output of sprintf(). And since PHP does its "type juggling", you can use $num1 as a float number in arithmetic operations. If you wanted to print the rounded number directly to output, then use printf ("%.2f", $num2); As others have pointed out in this thread, there are other--perhaps better--ways of doing this. I would prefer to do it this way because if you ever need to do it in perl or C, you'll already know how. This is what I love about programming: there can be literally hundreds of ways of doing any one simple thing. Sometimes, I like coming up with the more obscure methods. ;o) Good luck! Stephen. Ben-Nes Michael wrote: > > Hi > > how do i round float to two numbers after the dot ? > 4.234 = 4.23 > 5.689 = 5.69 > -- Computer Terms: Programmer - A red-eyed, mumbling mammal capable of conversing with inanimate objects. Stephen Hui, ARL:UT, Austin, TX

« previous php.general (#3396) next »