Question: `number_format` **stupidly** rounds numbers by default. Is there just a simple way to turn off the rounding? I'm working with randomly generated numbers, and I could get things like...

42533 \* .003 = 127.599 or,  

42533 \* .03 = 1275.99 or,  

42533 \* .3 = 12759.9

I need number\_format (or something else) to express the result in traditional U.S. format (with a comma separating the thousands) and **not** round the decimal.

Any ideas?

Answer: 
The second argument of [number\_format](http://php.net/number_format) is the number of decimals in the number. The easiest way to find that out is probably to treat it as a string (as per [this question](https://stackoverflow.com/questions/2430084/php-get-number-of-decimal-digits)). Traditional US format is default behaviour, so you don't need to specify remaining arguments.

```
$num_decimals = strlen(substr(strrchr($number, "."), 1));
$formatted_number = number_format($number, $num_decimals);

```
I tried these solutions, but what ended up being my answer was this:

```
$output=money_format('%!i', $value);

```

This gives you something like 3,234.90 instead of 3,234 or 3,234.9