Trailing zeros missing after subtraction
            3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 27, 2011   (RSS)          
          Hi all,
Small math problem here...
I'm offering a 10% discount to certain members and also refunding a registration fee if required.
The 10% works fine and trailing zeros are always shown.
The problem is that if the result of the subtraction has a trailing zero, the trailing zero disappears.
Any thoughts?
Thanks,
Jerry Kornbluth
Here’s the code I’m using:
First I define a variable to calculate a 10% discount
And one for the registration fee amount:
Then if the registration fee needs to be refunded, I’m using:
        Small math problem here...
I'm offering a 10% discount to certain members and also refunding a registration fee if required.
The 10% works fine and trailing zeros are always shown.
The problem is that if the result of the subtraction has a trailing zero, the trailing zero disappears.
Any thoughts?
Thanks,
Jerry Kornbluth
Here’s the code I’m using:
First I define a variable to calculate a 10% discount
<?php $price_a = number_format($record['1_hour_session_price']*.90,2); ?>And one for the registration fee amount:
<?php $deposit_amount  =  number_format($common_informationRecord['deposit_amount'],2); ?>Then if the registration fee needs to be refunded, I’m using:
<?PHP if ($CURRENT_USER['registration_fee_refund'] == 1): ?><?php echo $price_a - $deposit_amount  ?><?php else: ?><?php echo $price_a ?><?PHP endif ?>                          
      The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
                    Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Trailing zeros missing after subtraction
By Jason - January 27, 2011
          Hi Jerry,
What you can do is use number_format to force a certain number of decimal places.
Example:
This will force 2 decimal places to your number, even if they're zeros.
Hope this helps
                          
        What you can do is use number_format to force a certain number of decimal places.
Example:
<?PHP if ($CURRENT_USER['registration_fee_refund'] == 1): ?><?php echo number_format(($price_a - $deposit_amount),2);  ?><?php else: ?><?php echo number_format($price_a,2); ?><?PHP endif ?>This will force 2 decimal places to your number, even if they're zeros.
Hope this helps
      ---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
                    Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Trailing zeros missing after subtraction
          Thanks, 
I (erroneously) thought that it would be enough to include number_format in the defined variables.
Jerry
                          
        I (erroneously) thought that it would be enough to include number_format in the defined variables.
Jerry
      The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
                    Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php