CalcBuilder Forum

Numbers after comma

User moon_1785 2014-08-28 09:13:53

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

Moonsoft support 2014-08-28 10:12:28

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,

...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!
...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!