Thursday, March 18, 2010

Working with Float values

While you are working with float numbers and you should always want to display 1 or 2 numbers only after precission ex: You like to display 5.30 instead of 5.29088388434. To display in that format we have to use below functions

In Ruby:

f=1.23456
puts sprintf('%.2f', f).sub(/0{1,2}$/, '')

In php:
$$grandtotal = $rate*$miles;
echo number_format($grandtotal,2);
?>