Calculating miles per gallon Access 2007

F

Fly Boy 5

I have two field as Long Integer. Gas purchased and miles driven.

It calculates ok but rounds 10.5 gallons to 11. How can I set it up so it
will calculate tenths of gallons and tenths of miles?

Thanks
 
K

Ken Snell \(MVP\)

Change the Field Size of the Gas purchased field to Currency or to Single or
to Double. You're trying to store a fractional number in an integer field;
won't work.
 
F

Fly Boy 5

I changed the table fields to single and decimal to 1.
It still don't change until I change from 10 to 10.6 gallons which it will
indicate 27 from 30 mpg. Miles won't change until I go from 300.0 to 310.0.
which will indicate from 30 to 31mpg.
This is the formula I'm using in the query.
Expr1: +[Miles_Driven]\[Gallons_Purchased]

Any suggestions would be appreciated
 
K

Ken Snell \(MVP\)

Currency is a data type that keeps accurate numbers to four decimal places.
It's not just for currency data -- it's used often for numbers that can have
up to four decimal places when you want exact numbers, not "floating point"
numbers. Makes your calculations more accurate too.
--

Ken Snell
<MS ACCESS MVP>
 
K

Ken Snell \(MVP\)

You're using integer division when you use the \ operator. Try this:

Expr1: [Miles_Driven]/[Gallons_Purchased]

--

Ken Snell
<MS ACCESS MVP>



Fly Boy 5 said:
I changed the table fields to single and decimal to 1.
It still don't change until I change from 10 to 10.6 gallons which it
will
indicate 27 from 30 mpg. Miles won't change until I go from 300.0 to
310.0.
which will indicate from 30 to 31mpg.
This is the formula I'm using in the query.
Expr1: +[Miles_Driven]\[Gallons_Purchased]

Any suggestions would be appreciated

Ken Snell (MVP) said:
Change the Field Size of the Gas purchased field to Currency or to Single
or
to Double. You're trying to store a fractional number in an integer
field;
won't work.
 
F

Fly Boy 5

Thank you very much. Its working fine with double.


Ken Snell (MVP) said:
You're using integer division when you use the \ operator. Try this:

Expr1: [Miles_Driven]/[Gallons_Purchased]

--

Ken Snell
<MS ACCESS MVP>



Fly Boy 5 said:
I changed the table fields to single and decimal to 1.
It still don't change until I change from 10 to 10.6 gallons which it
will
indicate 27 from 30 mpg. Miles won't change until I go from 300.0 to
310.0.
which will indicate from 30 to 31mpg.
This is the formula I'm using in the query.
Expr1: +[Miles_Driven]\[Gallons_Purchased]

Any suggestions would be appreciated

Ken Snell (MVP) said:
Change the Field Size of the Gas purchased field to Currency or to Single
or
to Double. You're trying to store a fractional number in an integer
field;
won't work.

--

Ken Snell
<MS ACCESS MVP>


I have two field as Long Integer. Gas purchased and miles driven.

It calculates ok but rounds 10.5 gallons to 11. How can I set it up so
it
will calculate tenths of gallons and tenths of miles?

Thanks
 

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

Top