Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncating A Number Value (No Decimals)

Status
Not open for further replies.

FontanaS

Programmer
May 1, 2001
357
US
I have the following calculations -
lvAccountTaxes = lvAccountFunds * Request("AccountTaxes")

The problem is that i don't want any decimal places returned.

EX - lvAccountTaxes = 12589 * .17
I would like returned - 2140 NOT 2140.13
Is there a way to do that?

THANKS!
 
In addition to Matt's post you could also have a look at two other possible options.

I'm not sure if they would cause any possible problems with some values but here goes.

In your example you could declare lvAccountTaxes as an Integer (or Long) datatype. They only support whole numbers.

Or you could try using CInt if you don't want to declare it as an Integer. E.g.
Code:
lvAccountTaxes = CInt(12589 * .17)
As I said, I'm not sure if these will work correctly for all values but they both return your desired result.

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Try this. Make your variable a Long Integer.

Dim lvAccountTaxes As Long
lvAccountTaxes = 12589 * 0.17
 
There's also a "banker's rounding" concept that needs to be taken into account. "Normal" rounding rounds up if the rounded part is exactly 5. "Banker's" rounding rounds up if the rounded part is exactly 5 and the next more significant digit is odd, and down if it is even. This eliminates the rounding bias inherent in always rounding the number 5 up. (So, for example, 1.5 and 2.5 both round to 2.)

The round function, and all the conversion functions that imply rounding (csng, clng, cint, etc.) all use banker's rounding. (Note that CInt does NOT truncate the fractional part of a number as does the Int function, rather it rounds it.) The format function uses normal rounding.

For more:
HTH

Bob
 
OP actually asked for truncate rather than round. He will do better with the Int() function or the Fix() function

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Yes, well, john, OP might have been asking for banker's rounding to the nearest whole number too, hence my post.

:)

Bob
 
[smile] Bob, I suppose I was fooled by the thread title <q>Truncating A Number Value</q> [smile]

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Truncating. It does say that, doesn't it? Guess I didn't digest the title. Ok, I'm wrong on this one. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top