"Right" expression won't recognize rightmost (end) zero in decimal

P

Philsey

I am trying to creat an update query that will take the decimal portion of a
number and multiply by 60, then create a new field with the result.
Everything works fine until I have an end zero in the decimal places.

Example: 33.4680

using "(Right([Example],5))*60" produces the result 208.08

I'm trying to get the result 28.08

Any help is appreciated, especially if you know a better way to be doing
this. In general, I'm trying to convert latitude and longitude coordinates
from decimal degrees to degrees, minutes and seconds.
 
G

Golfinray

The 5 will take the rightmost 5 number and multiply x 60. 3.4680 * 60 =
208.08. Use 4 instead.
 
J

Jerry Whittle

([Example] - CDbl([Example])) * 60

However when [Example] is 33.4680 or even 33.468, the above will return the
following due to floating point math errors:
28.0800000000002

You could wrap it in the Format function using Standard or Fixed if you only
want 2 places behind the decimal. Converting it to currency would also work
even better as it would keep it as a number instead of a string like Format
would.

CCur((33.468 - Cint(33.4699)) * 60)
 
J

John Spencer

First question is the field a number field or is it a text field storing
number characters?

Assuming it is a number field
(Example - Int(Example)) * 60

Assuming it is a text field.
(Val(Example) - Int(Val(example))) * 60


--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
J

John W. Vinson

I am trying to creat an update query that will take the decimal portion of a
number and multiply by 60, then create a new field with the result.
Everything works fine until I have an end zero in the decimal places.

Example: 33.4680

using "(Right([Example],5))*60" produces the result 208.08

I'm trying to get the result 28.08

Any help is appreciated, especially if you know a better way to be doing
this. In general, I'm trying to convert latitude and longitude coordinates
from decimal degrees to degrees, minutes and seconds.

Right() manipulates strings - and as you see, does wierd things when you try
to manipulate numbers. A number IS NOT A STRING.

Try an arithmetic expression instead:

60*([example] - Fix([example])
 

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