-1

my software showing a Grand Total like this 2.00192, 3.65826 but I want it to show like 2.00, 3.65 My codes:

<td rowspan="2"><label for="date" class="mb-0 col-sm-6"><?php echo display('grand_total')?>:</label>
                                  <label class="col-sm-6 p-0 mb-0">
                                    <input type="hidden" id="orggrandTotal" value="<?php echo $calvat+$itemtotal+$servicetotal-($discount+$pdiscount);?>" name="orggrandTotal">
                                    <input name="grandtotal" type="hidden" value="<?php echo $calvat+$itemtotal+$servicetotal-($discount+$pdiscount);?>" id="grandtotal" />
                                    <span class="badge badge-primary grandbg font-26"><strong>
                                    <?php if($currency->position==1){echo $currency->curr_icon;}?>
                                    <span id="caltotal"><?php echo $calvat+$itemtotal+$servicetotal-($discount+$pdiscount);?></span>
                                    <?php if($currency->position==2){echo $currency->curr_icon;}?>
                                </strong></span></label></td>
                              </tr>

I found some result on google, but those are not working.

  • 2
    Does this answer your question? [Show a number to two decimal places](https://stackoverflow.com/questions/4483540/show-a-number-to-two-decimal-places) – jspit Nov 18 '22 at 13:28

1 Answers1

0

One of the ways to define decimal value precision is rounding. You can use round($number, $precision)

With your example it would look like so:

round($calvat+$itemtotal+$servicetotal-($discount+$pdiscount), 2);

https://www.php.net/manual/en/function.round.php

Matt
  • 26
  • 3
  • 1
    round is not well suited to output a float value rounded to a certain number of decimal places. sprintf or number_format is better. – jspit Nov 18 '22 at 13:31