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

Perfect for small code changes or to correct any bug at your site

Buy now!
...
List Manager

Build different lists for your site

Buy now!