Limiting number of decimal places after calculations

  • Thread starter Thread starter callumsalfield
  • Start date Start date
C

callumsalfield

Him im using this code to calculate ratios:

Private Sub Staff_AfterUpdate()

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
[Staff_Pupil] = [Pupils] / [Staff]
[TotalAdults] = [Staff] + [OtherAdults]
[Adult_Pupil] = [Pupils] / [TotalAdults]

End Sub

I want to limit the output of the following two calculations to one
decimal point, if there an easy way? I have already set them to one
decimal point in the table design but this seems to have no effect when
they are calculated....

[Staff_Pupil] = [Pupils] / [Staff] and [Adult_Pupil] = [Pupils] /
[TotalAdults]

Any help appreciated

Cheers
 
Use the Round function
[Staff_Pupil] = Round([Pupils] / [Staff] , 1)

One other point of interest. If [Staff] is 0, you will get an error. Any
time you do a division operation, you should check for 0 before you do the
division. What you do about it depends on what the desired result is.
 
Thanks for your help, Staff cannot be zero so should not be a
problem...

Use the Round function
[Staff_Pupil] = Round([Pupils] / [Staff] , 1)

One other point of interest. If [Staff] is 0, you will get an error. Any
time you do a division operation, you should check for 0 before you do the
division. What you do about it depends on what the desired result is.

Him im using this code to calculate ratios:

Private Sub Staff_AfterUpdate()

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
[Staff_Pupil] = [Pupils] / [Staff]
[TotalAdults] = [Staff] + [OtherAdults]
[Adult_Pupil] = [Pupils] / [TotalAdults]

End Sub

I want to limit the output of the following two calculations to one
decimal point, if there an easy way? I have already set them to one
decimal point in the table design but this seems to have no effect when
they are calculated....

and [Adult_Pupil] = [Pupils] /
[TotalAdults]

Any help appreciated

Cheers
 
I suspected as much, but it still is a good idea to keep in mind.

"There should be no problem getting to New York"
- Captain Smith of the Titanic on leaving Southhampton

cal said:
Thanks for your help, Staff cannot be zero so should not be a
problem...

Use the Round function
[Staff_Pupil] = Round([Pupils] / [Staff] , 1)

One other point of interest. If [Staff] is 0, you will get an error. Any
time you do a division operation, you should check for 0 before you do the
division. What you do about it depends on what the desired result is.

Him im using this code to calculate ratios:

Private Sub Staff_AfterUpdate()

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
[Staff_Pupil] = [Pupils] / [Staff]
[TotalAdults] = [Staff] + [OtherAdults]
[Adult_Pupil] = [Pupils] / [TotalAdults]

End Sub

I want to limit the output of the following two calculations to one
decimal point, if there an easy way? I have already set them to one
decimal point in the table design but this seems to have no effect when
they are calculated....

and [Adult_Pupil] = [Pupils] /
[TotalAdults]

Any help appreciated

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top