MS Access 2003 - Format a Number with Commas AND Auto-Decimal

Posted by Emtucifor on Super User See other posts from Super User or by Emtucifor
Published on 2010-04-08T01:54:42Z Indexed on 2010/04/08 2:03 UTC
Read the original article Hit count: 696

On a report I have a control which is bound to a column which can have up to 3 decimal places.

I want the number to format with commas separating thousands and millions, but I also want the number of decimal places to be automatic, so that if there is no decimal portion then no decimal at all is shown.

1234.567 -> 1,234.567
1234.560 ->  1,234.56
1234.500 ->   1,234.5
1234.000 ->     1,234

General format will give me the auto decimal places but no commas. Standard format gives the comma but is fixed to 2 decimal places. Doing my own =Format(Number, "#,##0.#") leaves the decimal point in and doesn't align properly, with extra space on the right of the number.

Do I have to write my own VB function to give the format I want? It seems silly that Access (apparently) can't do this out of the box.

This also seems really horrible:

=Replace(Replace(Replace(Replace(Replace( _
  Format(Number, "#,##0.000") & "x", "0x", ""), "0x", ""), "0x, ""), ".x", ""), "x", "")

© Super User or respective owner

Related posts about microsoft-office

Related posts about number-format