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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting double to long 2

Status
Not open for further replies.

zyrag

IS-IT--Management
Dec 4, 2002
252
PH
Is using the function Clng will do enough converting a double value into long integer?

lngNum=Clng(dblNum)

Will lngNum contain the rounded-off value?

Thanks,
 
>Is using the function Clng will do enough converting a double value into long integer?
Yes. As long as you do not try to convert a number beyond the limitations of an integer (the integer portion)
>Will lngNum contain the rounded-off value?
Yes. But rounded using statistical rounding when the last digit to be rounded is a 5 (1.5 = 2; 2.5 = 2, 3.5 = 4; 4.5 = 4; etc.).

 
Clng will convert a number to a Long integer. It will round any fraction. Note that the range of a Long is - (2^32) to (2^32) -1, and trying to convert doubles outside this range will result in a trappable error.

You can find this sort of stuff easily if you type Clng in the immediate or code window, put the cursor on it and hit F1. There's more on this in faq222-2244

________________________________________________________________
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?'
 
> 4.5=4? Is this right CCLINT?

Is there a function for rounding-off purposes?
 
Ye! As CCLINT stated, this is statistical rounding!

Do a search on this forum, and forum222 for 'rounding' as the subject has been covered very fully

________________________________________________________________
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?'
 

You can use the Format$() function for this:

= CLng(Format$(TheNumber, "0"))
 

>You can use the Format$() function for this:

If you use XP, then make sure you have Service Pack 1 when using the Format$() function for rounding numbers...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top