Rounding up numbers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On a form I have two fields:
[ProductionNorm]
[WageBase]

I would like to have a text box calculate a piece rate
([WageBase]/[ProductionNorm]) that rounds up the results to 4 decimal places.

example: [WageBase]/[ProductionNorm] 7.5/260 = .028846153 I would want
the results to say .0289

Can this be done?
 
Rick, Thanks for your response. Setting the control to 4 limits the results
to 4 decimal places, but doesn't Round Up. What I need is to round up the 4th
decimal place something like this:

If the results is .0261235 then I need it to show .0262
I know if you use the Round function, it will round numbers 1 thru 4 down
and 5 thru 9 up. What I need is no matter what the 5th decimal is, the 4th
will round up to the next number. I hope I expressed this clearly. Can this
be done?

Rick B said:
Sure. Just set the control's "decimals" property to 4.

--
Rick B



MikeG said:
On a form I have two fields:
[ProductionNorm]
[WageBase]

I would like to have a text box calculate a piece rate
([WageBase]/[ProductionNorm]) that rounds up the results to 4 decimal places.

example: [WageBase]/[ProductionNorm] 7.5/260 = .028846153 I would want
the results to say .0289

Can this be done?
 
Hi there,
Since you are asking for an abnormal thing (forth digit always rounded up),
then you should do some text manipulations to get the required result.

Here is a function which will return the value you need:
you should supply this function with the two input fields while calling it.

=========================
=========================
Private Function GetRequiredNumber(ProdNorm as Long, WB as Long) as Long
Dim OriginalDivisionResult as String
Dim IntegerPart as String
Dim Final as String

'getting the integer part only and converting it to STRING
IntegerPart=Trim(Str(Int(WB/ProdNorm)))

'converting the entire result to a string with no preceding spaces.
OriginalDivisionResult=Trim(Str(WB/ProdNorm))

Final= IntegerPart & Mid(OriginalDivisionResult, Len(IntegerPart)+1,4) &
(Val(Mid(OriginalDivisionResult, Len(IntegerPart)+5,1)+1)

GetRequiredNumber=Val(Final)
End Function
============================
============================

What this function will do is, it will convert the devision resulting number
into a STRING, then it will take the INTEGER, the DOT, and the first 3
dicimal digits as they are, then it will add ONE to the forth digit. Which
is exactly what you want.

Try it, and let me know if you have any problems.

Regards
Rashed
 
Rashed,
The TextBox for the division result is named Rate. Do I enter the function
in the Afterupdate event of this TextBox? If not, then where?

Rashed said:
Hi there,
Since you are asking for an abnormal thing (forth digit always rounded up),
then you should do some text manipulations to get the required result.

Here is a function which will return the value you need:
you should supply this function with the two input fields while calling it.

=========================
=========================
Private Function GetRequiredNumber(ProdNorm as Long, WB as Long) as Long
Dim OriginalDivisionResult as String
Dim IntegerPart as String
Dim Final as String

'getting the integer part only and converting it to STRING
IntegerPart=Trim(Str(Int(WB/ProdNorm)))

'converting the entire result to a string with no preceding spaces.
OriginalDivisionResult=Trim(Str(WB/ProdNorm))

Final= IntegerPart & Mid(OriginalDivisionResult, Len(IntegerPart)+1,4) &
(Val(Mid(OriginalDivisionResult, Len(IntegerPart)+5,1)+1)

GetRequiredNumber=Val(Final)
End Function
============================
============================

What this function will do is, it will convert the devision resulting number
into a STRING, then it will take the INTEGER, the DOT, and the first 3
dicimal digits as they are, then it will add ONE to the forth digit. Which
is exactly what you want.

Try it, and let me know if you have any problems.

Regards
Rashed




MikeG said:
On a form I have two fields:
[ProductionNorm]
[WageBase]

I would like to have a text box calculate a piece rate
([WageBase]/[ProductionNorm]) that rounds up the results to 4 decimal places.

example: [WageBase]/[ProductionNorm] 7.5/260 = .028846153 I would want
the results to say .0289

Can this be done?
 
Try this in the AfterUpdate event of WageBase and ProductionNorm.
If these fields are not entered on the form, put the code in the
OnCurrent event of the form.

Me!Answer=((Int((Me!WageBase/Me!ProductionNorm) * 10000) + 1) / 10000)

Ron
 
Back
Top