Can Not Stop Output Rouding Up

Rainbowhawk

Registered User.
Local time
Today, 16:53
Joined
Oct 8, 2007
Messages
54
Hi All

I have an issue with this piece of code

This code converts fuel in litres and Kilometres covered in to MPG

However when it writes the answer to the field it is populating the answer is being rounded, field is set as fixed to 2 decimal places.

I am using Access 97 (yep still in the dark ages)

Code:
[COLOR=black][FONT=Verdana]Dim g As Double[/FONT][/COLOR]
[FONT=Verdana][COLOR=black]Dim m As Double[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]Dim mp As Double[/COLOR][/FONT]
[COLOR=black][FONT=Verdana]g = Me.Fuel / 4.54609188[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]m = Me.TotalKms * 0.621371192[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]mp = m / g[/FONT][/COLOR]
[COLOR=black][FONT=Verdana]MsgBox mp 'shows answer on screen with loads of decimal places[/FONT][/COLOR]
[FONT=Verdana][COLOR=black]Me.MPG = mp 'is giving a rounded answer[/COLOR][/FONT]

All help appreciated
 
Have you tried adjusting the field decimal to auto to see what occurs once run, if you are running this on a form, then check the field properties of the text box as well
 
What format has your control got?
 
Don't use double if you are concerned about rounding. Use DECIMAL with a scale of 2. (there is a decimal datatype and there is a property there in the field properties which says SCALE. Set it to 2.
 
Found the issue, I had set the field as an Interger,

Also bob tried to use

Dim mp As Decimal

Is not available on my version access, not sure if its the version or the setup

All solved, cheers guys
 
tried to use

Dim mp As Decimal

Is not available on my version access, not sure if its the version or the setup

Decimal cannot be dimmed directly.
First dim as Variant then convert to Decimal

Dim mp As Variant
mp = CDec(mp)
 

Users who are viewing this thread

Back
Top Bottom