CalcBuilder Forum

2 Digits Result

User JoeCool 2011-12-06 00:19:54

after some operations, i've gotr a result. However i would like the result to be a 2 digits result, like 215.60€. I can only have an answer like 215.5985€.
Is there an easy way to obtain that kind of result ?
Thanks for your help.

Moonsoft support 2011-12-06 11:59:28

to format numbers before showing the results, you should use number_format function, where you can specify number of decimals and decimal/thousand separators. Usually this should be done at the last lines of the code, when all math is finished. To check an example we suggest to download and import the example calculator '4 basic operations & formatting numbers' here:

where you can see how different formatting are applied to the results.

Hope this helps, best regards
Moonsoft Team

User JoeCool 2011-12-06 12:28:40

Thanks, works like a charm !
Have a nice day.

Support/development 10 hours

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

Buy now!

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

Buy now!