ball420 Posted June 24, 2008 Share Posted June 24, 2008 I want to display the only two numbers after I multiply. example when multiplying 54.89 * .07 the answer is 3.8423 i only want to echo two numbers after the decimal. Is there a way to do this? Can somone guide me in the right direction I have tried to search google and just can't seem to find anything. thanks in advance for the guidance Link to comment https://forums.phpfreaks.com/topic/111597-solved-only-display-two-numbers/ Share on other sites More sharing options...
tpimental Posted June 24, 2008 Share Posted June 24, 2008 This should do it: <?php echo substr("Hello world!",4); //replace Hello World with your variable ?> Link to comment https://forums.phpfreaks.com/topic/111597-solved-only-display-two-numbers/#findComment-572820 Share on other sites More sharing options...
kenrbnsn Posted June 24, 2008 Share Posted June 24, 2008 Take a look at the function number_format(). You can also used sprintf(). Ken Link to comment https://forums.phpfreaks.com/topic/111597-solved-only-display-two-numbers/#findComment-572821 Share on other sites More sharing options...
ball420 Posted June 24, 2008 Author Share Posted June 24, 2008 thanks for the help everyone this was the solution i used thanks for the guidance $result = 54.89 * .07; echo number_format ("$result", 2); Link to comment https://forums.phpfreaks.com/topic/111597-solved-only-display-two-numbers/#findComment-572833 Share on other sites More sharing options...
kenrbnsn Posted June 24, 2008 Share Posted June 24, 2008 You don't have to surround the variable $result with double quotes. This works just as well: <?php echo number_format($result,2); ?> Ken Link to comment https://forums.phpfreaks.com/topic/111597-solved-only-display-two-numbers/#findComment-572836 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.