interactivepoint solutions

number_format()

We’ve tried many different methods to set precision for a number variable (specifically a currency amount) and we’d like to share the best method we’ve found:

number_format(
   {number},
   {precision},
   'decimal_separator',
   '1000s_separator' );

Example:

number_format( $number, 2, '.', ',' );

Hope this helps!

We have also tried using round( $number, {precision} ) but it ignores zeros(0) within the precision numbers.

Example:

$number = 9.90;
round( $number, 2 ); // returns: 9.9

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>