Summing query?

T

Tony Williams

I have a number of fields with a data format of Double, fixed 3 decimal
places. So why when I do run a query with say Sum([field 1]+[field 2]) do I
get an answer with 6 decimal places?
Intriguing?
Tony
 
G

Guest

Format is how the data is displayed - not how it is stored. Change your query
to:

Format2: Format(Sum([field 1]+[field 2]), "Fixed")

It's also possible that there is a floating point math problem.

Debug.Print 3.1 - 3.11 doesn't give you what you expect. If you always need
just 2 decimal points, converting the field to currency might be a solution.
 
T

Tony Williams

Thanks Jerry I'll have a look at your suggestions.
Tony
Jerry Whittle said:
Format is how the data is displayed - not how it is stored. Change your
query
to:

Format2: Format(Sum([field 1]+[field 2]), "Fixed")

It's also possible that there is a floating point math problem.

Debug.Print 3.1 - 3.11 doesn't give you what you expect. If you always
need
just 2 decimal points, converting the field to currency might be a
solution.

--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


Tony Williams said:
I have a number of fields with a data format of Double, fixed 3 decimal
places. So why when I do run a query with say Sum([field 1]+[field 2]) do
I
get an answer with 6 decimal places?
Intriguing?
Tony
 
T

Tony Williams

Jerry how do I then limit it to 0 decimal places?
Tony
Jerry Whittle said:
Format is how the data is displayed - not how it is stored. Change your
query
to:

Format2: Format(Sum([field 1]+[field 2]), "Fixed")

It's also possible that there is a floating point math problem.

Debug.Print 3.1 - 3.11 doesn't give you what you expect. If you always
need
just 2 decimal points, converting the field to currency might be a
solution.

--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


Tony Williams said:
I have a number of fields with a data format of Double, fixed 3 decimal
places. So why when I do run a query with say Sum([field 1]+[field 2]) do
I
get an answer with 6 decimal places?
Intriguing?
Tony
 
G

Guest

I noticed that you actually wanted 3 decimal places in the first place so
'Fixed' wouldn't work there either. Back to the drawling board....

Decimals3: Format(Sum([field 1]+[field 2]), "0.000")
Decimals0: Format(Sum([field 1]+[field 2]), "0")
or
Decimals0: CLng(Sum([field 1]+[field 2]))

There might be a slight difference in the rounding between the two Decimals0
above especially if you have any negative numbers.

--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

Tony Williams said:
Jerry how do I then limit it to 0 decimal places?
Tony
Jerry Whittle said:
Format is how the data is displayed - not how it is stored. Change your
query to:

Format2: Format(Sum([field 1]+[field 2]), "Fixed")

It's also possible that there is a floating point math problem.

Debug.Print 3.1 - 3.11 doesn't give you what you expect. If you always
need just 2 decimal points, converting the field to currency might be a
solution.

--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

Tony Williams said:
I have a number of fields with a data format of Double, fixed 3 decimal
places. So why when I do run a query with say Sum([field 1]+[field 2]) do
I get an answer with 6 decimal places?
Intriguing?
Tony
 
T

Tony Williams

Thanks jerry fixed the problem using Decimals3
Tony
Jerry Whittle said:
I noticed that you actually wanted 3 decimal places in the first place so
'Fixed' wouldn't work there either. Back to the drawling board....

Decimals3: Format(Sum([field 1]+[field 2]), "0.000")
Decimals0: Format(Sum([field 1]+[field 2]), "0")
or
Decimals0: CLng(Sum([field 1]+[field 2]))

There might be a slight difference in the rounding between the two
Decimals0
above especially if you have any negative numbers.

--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

Tony Williams said:
Jerry how do I then limit it to 0 decimal places?
Tony
Jerry Whittle said:
Format is how the data is displayed - not how it is stored. Change your
query to:

Format2: Format(Sum([field 1]+[field 2]), "Fixed")

It's also possible that there is a floating point math problem.

Debug.Print 3.1 - 3.11 doesn't give you what you expect. If you always
need just 2 decimal points, converting the field to currency might be a
solution.

--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

:

I have a number of fields with a data format of Double, fixed 3
decimal
places. So why when I do run a query with say Sum([field 1]+[field 2])
do
I get an answer with 6 decimal places?
Intriguing?
Tony
 

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