|
-
October 4th, 1999, 11:10 PM
#1
CInt rounds the number, but i need to display without rounding
When I use CInt(Text1) + CInt(Text2) in a formula, it rounds the answer..i need my answer without rounding......
Thank You
-
October 5th, 1999, 02:35 AM
#2
Re: CInt rounds the number, but i need to display without rounding
How about
Dim dblX as Double
Dim dblY as Double
If IsNumeric(Text1.Text) then
dblX = CDbl(Text1.Text)
else
MsgBox "Text1.Text Not Numeric"
Exit sub/function/whatever
End if
If IsNumeric(Text2.Text) then
dblY = CDbl(Text2.Text)
else
MsgBox "Text2.Text Not Numeric"
Exit sub/function/whatever
End if
MsgBox "Result = " & (dblX + dblY)
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
-
October 5th, 1999, 01:36 PM
#3
Re: CInt rounds the number, but i need to display without rounding
First of all what do you want to do exactly?
Add just the integer part?
For e.g if text1 = 3.6 and text2= 4.2
then Cint(text1) + Cint(text2) will give you 8
(4 + 4)
If you just want the integer part to be added i.e 3 + 4 to give 7 then use Fix()
-
October 6th, 1999, 01:13 AM
#4
Re: CInt rounds the number, but i need to display without rounding
why don't you try and use the simple Val function
for eg.,
Text1.Text = "4.85"
Text2.Text = "7.63"
msgbox val(text1.text) + val(text2.text)
should give you 12.48
-
October 6th, 1999, 02:22 AM
#5
Re: CInt rounds the number, but i need to display without rounding
'Val' is notoriously bad at converting values that aren't numbers into a number equivilent - there was an article in the MSDN a long time ago about the possible errors in using the function.
For instance, Val("123 Some Road")
Using the IsNumeric version will work regardless of what's typed in.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|