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
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
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()
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
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