Moonsoft Software Solutions

Numbers after comma

Started 28 Aug 2014 · 1 reply

  1. moon_1785
    Hi, how can I limit to 2 the number of decimal after the comma?
    Example: 51,12% not 51,123456789%

    This is the PHP code that I used to calculate percentage:

    $myresult=100/$number1 . '%';

    Thanks
  2. Moonsoft support
    Hi,

    You should use number_format php function (http://php.net/manual/es/function.number-format.php) like this:

    $myresult=number_format((100/$number1),2) . '%';

    If you want to decimal point of thousand separator, you should add 2 parameters to number_format function (Check docs).

    Regards,

Still stuck?

Customers with an active license can open a support ticket.

Log in to open a ticket