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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format the decimal places in a query

Status
Not open for further replies.

sonikudi

Technical User
Joined
Sep 9, 2007
Messages
81
Location
US
I have a query that outputs a percentage, something like this: 22.4719101123595, i want it to show only 2 decimal places.

My query as is, is shown below.

SELECT t1.[Item Num], t1.[Shipment Date], (t1.SumNumDefected/t1.SumBatchSize)*100 AS PercentRejected INTO qrySummaryStaubTable
FROM qryGetSummaryStaub AS t1;


Thanks!
 
Maybe this?

Code:
FormatPercent((t1.SumNumDefected/t1.SumBatchSize), 2)

would work for you?

Hope this helps,

Alex

[small]----signature below----[/small]
Now you can go where the people are one!
Now you can go where they get things done!
 
thanks for the suggestion, but it doesn't work. it just replaces all the numbers in the colums with '2', .


Any other suggestions?
 
Or paste this function into a module & call it:
Code:
Public Function RoundTotal(ByVal dblNumber As Double, ByVal intDecimals As Integer) As Double

  'Comments   : 
  '           : 0.5 is rounded up
  'Parameters : dblNumber - number to round
  '           : intDecimals - number of decimal places to round to
  '           : (positive for right of decimal, negative for left)
  'Returns    : Rounded number

    Dim dblFactor As Double
    Dim dblTemp As Double         ' Temp var to prevent rounding problems in INT()

    dblFactor = 10 ^ intDecimals
    dblTemp = dblNumber * dblFactor + 0.5
    RoundTotal = Int("" & dblTemp) / dblFactor
  
End Function
[/code

Depression is merely anger without enthusiasm.
 
Oops! Forgot the closing bracket on my TGML. Sorry!

Depression is merely anger without enthusiasm.
 
What version of Access are you using?



[small]----signature below----[/small]
Now you can go where the people are one!
Now you can go where they get things done!
 
I use XP (Access 2002).

Depression is merely anger without enthusiasm.
 
hey thanks, if you jus go under design view of the query and right click on the properties and you can specify the format there ..so didn't need to write a code or anything:)

but thanks for the help!!
 
Why do you think you need to format in a query? I generally set format properties in text boxes on forms and reports. Any formatting in a query/record source would just cause issues.

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