Limiting number of decimal places after calculations

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
 
K

Klatuu

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.
 
C

cal

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
 
K

Klatuu

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
 
Top