From: Nathan Rixham on 22 Jan 2010 20:10 Rick Dwyer wrote: > On Jan 22, 2010, at 7:30 PM, Nathan Rixham wrote: > Thanks Nathan I'll give it a shot. > np - here's a more condensed version: function round_to_half_cent( $value ) { $value = ($value*100) + 0.3; $out = number_format( floor($value)/100 , 2 ); return $out . ($value > .5+(int)$value ? '5' : ''); } >> >> echo round_to_half_cent( 12.1 ); // 12.10 >> echo round_to_half_cent( 12.103 ); // 12.105 >> echo round_to_half_cent( 12.107 ); // 12.11 >> echo round_to_half_cent( 123456.789 ); // 123,456.79 >>
From: Rick Dwyer on 22 Jan 2010 20:36 Thank you Nathan, This worked quite well. --Rick On Jan 22, 2010, at 8:10 PM, Nathan Rixham wrote: > Rick Dwyer wrote: >> On Jan 22, 2010, at 7:30 PM, Nathan Rixham wrote: >> Thanks Nathan I'll give it a shot. >> > > np - here's a more condensed version: > > function round_to_half_cent( $value ) > { > $value = ($value*100) + 0.3; > $out = number_format( floor($value)/100 , 2 ); > return $out . ($value > .5+(int)$value ? '5' : ''); > } > >>> >>> echo round_to_half_cent( 12.1 ); // 12.10 >>> echo round_to_half_cent( 12.103 ); // 12.105 >>> echo round_to_half_cent( 12.107 ); // 12.11 >>> echo round_to_half_cent( 123456.789 ); // 123,456.79 >>> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
First
|
Prev
|
Pages: 1 2 Prev: Help on compiling PHP for MIPS, Bus Error thrown Next: Weird Array Issue... |