Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

decimals query

Status
Not open for further replies.

phpatrick

Programmer
Jul 9, 2006
72
BE
perhaps its a dump question, but I can't find it right now.
I have a calculated field in my query and I like to limit the decimals to 2 digits. I looked in the properties, but this is not mention decimals. This query feeds my report, here I can limit the decimals, but he takes the complete value of the query (with many digits).

Code:
LOON: IIf(IsNull([LOONTO]);"";[LOONTO]*[TOTH])
 
Several possibilities
Code:
LOON: IIf(IsNull([LOONTO]);"";[red]Round([/red][LOONTO]*[TOTH][red],2)[/red])
Code:
LOON: IIf(IsNull([LOONTO]);"";[Red]Format([/red][LOONTO]*[TOTH][red],"0.00")[/red])
Code:
LOON: IIf(IsNull([LOONTO]);"";[red]CCur(CInt([/red][LOONTO]*[TOTH][red]*100)/100.0)[/red])
 
I'm not sure why you want to format in a query when records should be presented in a form or report where you set the Format property.

One mistake you are making is an IIf() that might return a number or might return a string. I think an IIf() should always return a single data type or null. Consider using an expression like:
LOON: IIf(IsNull([LOONTO]);Null;[LOONTO]*[TOTH])

This will have the same results as:
LOON: [LOONTO]*[TOTH]



Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top