Jump to content

[SOLVED] remove trailings 00


AnotherQuestion

Recommended Posts

Yes, number_format() is what you want.

 

$original = 12.3456789;
$two_decimal = number_format($original, 2);
//Output: 12.35

 

It will also have the effect of increasing the value to two decimals if less than two. In addition, it will round the value to two decimals if needed.

Link to comment
Share on other sites

thanks bundyxc your method worked.

 

final code used was

<?php $InvTotal = $row_RSInvoiceHeader['Invoice_Total'];
$point = strpos($InvTotal, '.');
$InvTotalSum = substr($InvTotal, 0, $point + 3); ?>
          <?php echo $InvTotalSum; ?>

 

 

Ok, you do realize that there is a built-in function within PHP to do exactly what you asked for which Mark Baker first suggested, right? But instead you decide to build a customer function for something PHP already does. Brilliant!  :facepalm:

 

You could replce those four lines of code with just this

echo number_format($row_RSInvoiceHeader['Invoice_Total'], 2);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.