Calculating miles per gallon Access 2007

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

Guest

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
 
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.
 
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
 
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>
 
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.
 
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
 
Back
Top