Reduce Decimal Places WITHOUT Rounding (1 Viewer)

Myriad_Rocker

Questioning Reality
Local time
Today, 04:36
Joined
Mar 26, 2004
Messages
166
Hey everyone! Hopefully, someone can help me with this. I've searched the forum and can't find anything on it.

I want to take a number and reduce the number of decimal places from 4 to 3 WITHOUT rounding it. Just chop off that 4th number...I don't care about it.

Examples:

243.4586 = 243.458
22.0541 = 22.054
5.8577 = 5.857
1,587.2556 = 1,587.255

Seeing as how the numbers can be in the 10's, 100's, and 1000's, I can't just use the LEFT function. :D That, of course, would be too easy.

Suggestions? Solutions?

Thanks in advance!
 

Rickster57

Registered User.
Local time
Today, 02:36
Joined
Nov 7, 2005
Messages
431
rounding

If you don't mibd using an expression in a query...


expr: Left([anumber],Len([anumber])-1)
 

Myriad_Rocker

Questioning Reality
Local time
Today, 04:36
Joined
Mar 26, 2004
Messages
166
That works but I forgot one thing.

The field will not always have 4 decimal places. Sometimes it will have 3, 2, 1, or even zero.
 

Rickster57

Registered User.
Local time
Today, 02:36
Joined
Nov 7, 2005
Messages
431
numbers

How many decimal places is there supposed to be in the final format then?
0?1?2?
 

Myriad_Rocker

Questioning Reality
Local time
Today, 04:36
Joined
Mar 26, 2004
Messages
166
Got it...

IIf(InStr([field],".")>0,(Left([field],(InStr([field],".")))) & (Mid([field],(InStr([field],".")+1),3)),[field])
 

Jon K

Registered User.
Local time
Today, 10:36
Joined
May 22, 2002
Messages
2,209
Left([Field], InStr([Field],".")+3)
.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:36
Joined
Feb 19, 2002
Messages
43,257
You can't rely on string functions to work correctly on numeric fields. If you want to use string functions, you must first convert the numeric value to a string by using the Format() function.

I actually have a sub that will truncate or round to a specific number of decimal places but it is way past my bed time. Search here, I may have posted it or PM me with a link to this thread and I'll look for it tomorrow.
 

bluetongue

Registered User.
Local time
Today, 19:36
Joined
Jul 15, 2004
Messages
34
assume the field you wish to truncate is called var

use INT(var*1000)/1000 if var is negative or
FIX(var*1000)/1000 if var is positive

the Help file says
"Both Int and Fix remove the fractional part of number and return the resulting integer value.

The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8."
 

Users who are viewing this thread

Top Bottom