Voodoo Jai Posted October 3, 2008 Share Posted October 3, 2008 Hi again all I have 2 variables that I take from my database that are of the type FLOAT what I want to do is add them together to give a FLOAT value. My problem is that I want it to show the figures after the decimal point even if they are ZERO figures. <?php $ListFee = "58.00"; $BorderFee = "12.00"; $TotalAmount = ($ListFee + $BorderFee); echo $TotalAmount; ?> the output gives me 70 I want 70.00 Many thanks in advance again VoodooJai Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/ Share on other sites More sharing options...
nadeemshafi9 Posted October 3, 2008 Share Posted October 3, 2008 do a search for float or something in the php manual Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/#findComment-656278 Share on other sites More sharing options...
mursalat Posted October 3, 2008 Share Posted October 3, 2008 just add a .00 to it when you echo it, php only gives to decimal places if there is any value in decimal places. Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/#findComment-656280 Share on other sites More sharing options...
thebadbad Posted October 3, 2008 Share Posted October 3, 2008 <?php echo round($TotalAmount, 2); ?> Edit: Sorry, doesn't work. This should: <?php echo number_format($TotalAmount, 2, '.', ''); ?> Uses a dot for decimal point, and nothing for thousands separator. Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/#findComment-656286 Share on other sites More sharing options...
Voodoo Jai Posted October 3, 2008 Author Share Posted October 3, 2008 <?php echo round($TotalAmount, 2); ?> This still does not give me the ZERO's after the INT didgits. Have looked at the PHP manual but don't understand what I am looking for exactly. Cheers all. Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/#findComment-656289 Share on other sites More sharing options...
Voodoo Jai Posted October 3, 2008 Author Share Posted October 3, 2008 Got it eventually thanks all $ListFee = 58.00; $BorderFee = 12.00; $TotalAmount = $ListFee + $BorderFee; $Amount = printf("%01.2f", $TotalAmount); Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/#findComment-656295 Share on other sites More sharing options...
thebadbad Posted October 3, 2008 Share Posted October 3, 2008 Guess you didn't notice my edit Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/#findComment-656297 Share on other sites More sharing options...
nadeemshafi9 Posted October 3, 2008 Share Posted October 3, 2008 thats not the proper way to do it, you need to specify decimal percission Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/#findComment-656365 Share on other sites More sharing options...
thebadbad Posted October 3, 2008 Share Posted October 3, 2008 thats not the proper way to do it, you need to specify decimal percission Agree, he should use number_format() like I suggested. Quote Link to comment https://forums.phpfreaks.com/topic/126888-solved-define-a-variable-to-a-float-type/#findComment-656604 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.